
Over the last month I’ve slowly begun exploring Node.js and so far I’m really liking what I’m seeing.
In a nutshell, Node.js (or simply Node) allows you to write server-side JavaScript. In other words, until now JavaScript is normally written to be run within a web browser, on a web page. Node instead allows you to write JavaScript applications that run outside the browser or via the command line.
Node uses Google Chrome’s JavaScript engine, called V8. Perfect if you are used to writing JavaScript for your browser.
This means that you can now write applications, or ‘modules’ that can do stuff outside the scope of a web browser. For example, you could write a simple web server in Node or — and this is what I want to use it for — you could write modules to manipulate web code and automate certain processes related to web development.
Installing Node.js
Installation on Windows 8 could not have been any more straight forward:
- Visit nodejs.org
- Click the “install” button to download the installer.
- Run the installer (make sure you tell the installer to add references to your PATH system variables).
- Reboot your PC.
- Er…
- That’s it!
Command line
Almost everything you do with Node is via a command line. You can use either the standard Windows cmd.exe or Windows PowerShell (or, indeed, any other command line interpreter (CLI) you may have installed).
To use the standard Windows command line:
- Press Win + R (for Run)
- Type: CMD
- Click OK
Checking that Node is installed is as simple as opening a command line and typing:
node --version
Hit enter and you’ll get a result, something like:
v0.10.5
Node Package Manager
One of the great things about the Node installer is that it automatically installs the Node Package Manager. This makes it much easier to install additional applications to extend Node’s capabilities.
Again, you can check the version of NPM by typing the following into your CLI:
npm version
You’ll get an answer, returned as a JSON object:
{ http_parser: '1.0', node: '0.10.5', v8: '3.14.5.8', ares: '1.9.0-DEV', uv: '0.10.5', zlib: '1.2.3', modules: '11', openssl: '1.0.1e', npm: '1.2.18' }
To find out what packages are installed enter the following into your CLI:
npm ls
The result will be formatted as a directory structure, like this:
C:\Users\Gareth ├── [email protected] └── [email protected]
Obviously, to find out which globally-installed packages are available use the global flag:
npm ls -g
The first application/module that I want to investigate in depth is the CSS pre-processor Less which is used by the Bootstrap project. I will no doubt report back.
Its very clean and perfect explanation. A kid can also understand the way way you documented without missing anything and this helped me as a beginner.
Thanks
It’s great and very easy to understand. It gave me a big help to start nodejs. Thanks.
Hi Gareth,
Thanks for posting this very useful tutorial. I was at a lost before I found this I tried to follow the official node website but failed to make node.js run. Good job!
Best Regards,
Jun
You’re welcome. I often write things like this to remind myself when I need to come to do it again. I’m glad it helps others too.
Hi
thanks for sharing
my nmp give’s Error
how can i fix it
— i am getting error —
events.js:72
throw er; // Unhandled ‘error’ event
^
Error: spawn ENOENT
at errnoException (child_process.js:975:11)
at Process.ChildProcess._handle.onexit (child_process.js:766:34)
——— my code look like this ———
var curl = require(‘curlrequest’);
var express = require(‘express’);
var app = express();
var options = {
url: “https://api.github.com/repos/jiangmiao/node-curl”,
encoding: null,
//, headers: { ‘foo bar’: ‘wha’ }
};
curl.request(options, function (err, data, meta) {
data = JSON.parse(data.toString());
console.log(data);
});
i am on 0.10.33, after you install nodjs, directory creation is required
mkdir C:\Users\UserName\AppData\Roaming\npm
After installing the nodejs i was using the command node –version and after enter the cmd shows “node.js is not recognized in internal or external command “
Try “node -v” instead -version
very easy ,thanks
thanks 🙂
First, thanks for the post, very clear.
Comment I have a problem to install global packet (-g) with NPM and do not charge me node_modules, but remains in an endless process.
My path when downloading nodejs is C: Program Files nodejs.
I would appreciate knowing if there are similar cases and what is the solution.
From already thank you.
Gareth, thanks for the great article.
As you are the only one I have found writing about node.js and the windows CLI, I though you may have a hint about what’s going on in the CLI:
==========
C:UsersChris>ver
Microsoft Windows [Version 10.0.10240]
C:UsersChris>node –version
v4.0.0
C:UsersChris>node -e ‘console.log(“Hi, planet!”)’
// node -e “console.log(‘Hi, planet!’)”
Hi, planet!
===========
Why must the double-prime quotation mark be the “outside” wrapper on the in-line script?
Thanks.
Oops! that didn’t work. Lets try that CLI again:
C:UsersChris>ver
Microsoft Windows [Version 10.0.10240]
C:UsersChris>node –version
v4.0.0
C:UsersChris>node -e ‘console.log(“Hi, planet!”)’
C:UsersChris>node -e “console.log(‘Hi, planet!’)”
Hi, planet!
C:UsersChris>==========
Note: no output from the first invocation.
hey!!
installed nodejs on my windows 8.1 successfully but there is no installed packages or globally installed packages available.
coz the result is empty when i run the command npm ls and npm ls -g
what should i do??
as i want to install bower and serve through npm!!
Thanks in advance 🙂
Thanks sir . It’s great article for install node js in own system. I am beginner of node js . I did not know that how to install node js. But I followed your article steps than i installed node js in own system. Thanks once again.