Getting Started With Node.JS On Windows

Written by
Published on
Modified on

For a .NET developer I do sure spend alot of time working with JavaScript. And that's alright, variety is the spice of life. And so this week I'll be tackling Node.js. I've seen tons of cool Node.js examples online and I can see the benefit in it in some of my projects and now it's time for me to dive right in and try it out for myself. I firmly believe that the best way to learn anything new is to just start using it. You can spend hours and days reading tutorials and memorizing some keywords, just to have to sit there for months on a real world project not knowing how implement it. So let's start typing and see what develops.

Step 1: Download and Installs Node.JS

Before you begin to do anything you need the software installed, and so let's head on over to the official node.js website and download the Node.js installer for Windows. It's a fairly straight forward download. You pick your Windows version, 32 or 64 bit and you download and install it. After you install it, nothing happens pretty much, but it's there and ready to be run you can be sure of that.

download node.js

Open up your command line interface. You can do that by holding the Windows key and typing 'r' (Run window opens) and then typing cmd into the search field. Or any other way that you prefer to open up your command line interface.

Step 2: Run A Few Test Commands

Let's first test that Node.js installed correctly. Node.js comes built in with npm, which is a JavaScript package manager. If everything installed correctly then you should see the following screen when you type the npm command.

npm command screen

If you already have npm installed then this test is moot, and so from the console we can launch Node.js with the node command, which puts the console into Node.js editor mode, if you will. From here you can type and run any JavaScript that you wish. For example, here are a few JavaScript commands I threw into the editor.

As you can see you can run pretty much any JavaScript right from your console window. Pretty neat. You can also output content using the console.log command that many of us are used to using daily.

Step 3: Load A JavaScript File

We can also pass JavaScript files into Node too, which is probably how we'll mainly be working with Node.js. For example here is a quick file I made which I titled "testnode.js" with the following content.

var a = 1;
var b = 2;
var c = 3;

console.log("a: " + a);
console.log("b: " + b);
console.log("c: " + c);

console.log("a + c: " + (a + c));

And here is what that looks like when we run it:

As you can see Node read the file and executed all of the commands present right on my machine no browser required.

Step 4: Run The Interactive Tutorial

The best way to learn is by doing, and has a fantastic Node.js interactive tutorial that you can download and install through the npm package manager that will show you the basic use cases and scenarios that you will encounter when using node.js. So let's set that up. Go into your command line, like we did above, and type the following command:

npm install -g learnyounode

Let your command buzz and whir for a minute or two (it took a while on my machine) after this while everything gets installed. Once done, simply run the tutorial with the following:


And you'll get the following. A series of 13 interactive tutorials to help you wade your way through the many intricacies of Node.js. After you complete each exercise, your result will be verified and upon completion will be marked as "Complete". Pretty nifty if you ask me. So let's run through the first exercise on the list while we're here.

learnyounode home screen

Exercise #1

The exercises start off pretty simple and get progressively more complex as you complete them. Here's the first exercise, in which our task is to output "HELLO WORLD" using node.js onto the console window.

learn you node exercise 1
learnyounode exercise 1

The solution here is simply to create a new JavaScript file, title it program.js and have the following inside of it. And yes, we can use the standard JavaScript output methods in Node.JS to view the results, which is pretty cool.

console.log("HELLO WORLD");

Save that, and place it in a directory that's easy to reach from the command line (something close to the C:/ drive perhaps) and we run that script using the learnyounode verify program.js command and we are done with Exercise #1.

By the time we're done with all of the exercises we'll be running our own server written in Node and doing many more cool things. I'm only going to cover Example #1 and leave the rest of the exercises up to those who enjoy learning for themselves. And I myself will be tackling on more complex node examples while I'm at it. And I'll have a follow up soon as to how that is going.

Comments & Questions

No messages posted yet

Add a comment

Send me your weekly newsletter filled with awesome ideas