Setup Environment on Windows machine for Node.js Development

I am aspired to learn Node and I had tough time setting up environment for Node development. Guess what I got none other than Mr Glenn Block to help me. We did pair programming over Google Hangout and he helped me setting up. It was his kindness that he spent time with me. He has been inspiring many like me and helping developers around. He has done great work on Node and you can read few of his learning material at below link,

https://github.com/glennblock/node-azure-workshop/blob/master/part1_basics_01.md

This blog post is dedicated to Glenn. Language of this blog post is in the way that I am talking to you however this blog is just text version of Glenn work done with me while doing pair programming.

Yes I know you are excited for Node.JS. You know Node runs your script at server rather at the client browser. Cool, now let us see how we can set up development environment for Node development. You have choice to use any text editor of your choice to work with Node. I am choosing Sublime Text 2 as editor to write code. So put your sleeves on and follow following steps to set up environment.

Step 1: Download and Install in Node.JS

Navigate to http://nodejs.org/ and click on download.

clip_image002

You will be navigated to download page. From here select required installer, download that and then install that. I am working on Windows machine so I selected option of Windows Installer.

After successful installation go to shell and verify successful installation. To verify it type npm on command prompt and you should get output as given below. It also verify that node is successfully added to the path.

clip_image004

There is another option to install node as well. You can install it from chocolatey.

http://www.chocolatey.org/packages/nodejs.install

Step2: Install Sublime Text

As we discussed in beginning of this post, you can work with any text editor of your choice to work with Node. We selected Sublime Text. You can grab sublime from here

http://www.sublimetext.com/2

After downloading and installing navigate to https://sublime.wbond.net/installation#st2 . From here you need to install package in Sublime Text. Choose package for installed sublime text version. In my case it is Sublime Text2. Copy text for package from here.

clip_image002[6]

Now launch Sublime Text and open console. To open console you have two options

  1. View-> Show Console
  2. Type shortcut ctrl + `

On console paste copied text from previous step and press Enter. After package got installed we need to enable node package on Sublime Text. To enable this go to Tools-> Command Palette(Ctrl+ Shift+P) and search Node and install.

Once this is done you need to create working folder. You can create working folder anywhere. I have created a folder named NodeCodes in C drive. After creating folder we need to add folder to project. To do this navigate to Project -> Add Folder to Project. I have added NodeCodes folder as project.

clip_image001

Now you are good to go and environment for Node development has been setup at your machine.

Write Hello World and Run it

Now go ahead and create a file named Server.js in your working folder. In my case it is NodeCodes folder. In Server.js write below code. In further posts we will go into detail of these codes. As of now just copy paste them to run your first Node program.

Server.js


var http = require('http');
http.createServer(function (req, res) {
 res.writeHead(200, {'Content-Type': 'text/plain'});
 res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

Now to run this go to command prompt and type Node Server.js . If you are not in working folder then do not forget to pass full path of Server.js

clip_image001[5]

As output you should get server running message.

clip_image002

Once you get this output means your development environment is up and you are good to play around Node. In further post I will discuss other topics of Node and try to simplify Node learning. Once again Thanks to Glenn for his support.

8 responses to “Setup Environment on Windows machine for Node.js Development”

  1. Nice job man, it was fun. One thing to mention, you don’t NEED the sublime plugin for Node. The advantage of using it is it gives you better syntax completion for core node APIs and it adds a Node build so you can do Ctrl+B to run the app from within Sublime.

  2. Dhananjay Kumar

    Hi Glenn ,

    I will update this on blog 🙂 Thanks for all support

  3. Good Post friend. It is nice to learn new tech with you 🙂

  4. Dhananjay Kumar

    Thanks Mayanak

  5. […] Cómo configurar NodeJS en entorno Windows: Yo simplemente con el instalador de la web de Node me ha sido suficiente, pero hay alguna otra forma. […]

  6. […] Setup Environment on Windows machine for Node.js Development: Part 1 […]

  7. Nice article… tnk u sir 4 posting…

  8. […] Setup Environment on Windows machine for Node.js Development [Set up Sublime Text] […]

Leave a comment

Create a website or blog at WordPress.com