Getting Started With Node.js on Windows

By

September 18, 2013Framework JavascriptNo comments

Node JS is a Server Side Javascript Framework. Getting Started With Node.js on Windows is pretty simple. With Node JS in place we can create web applications that uses javascript for both client side as well as for Server side.

Node JS Acts as a Web server.

Getting Started With Node.js on Windows development Environment:-

Step 1:- To Install Node JS we can either install the entire source files
or we can use Installer that takes care of installing node JS by running installation wizard
with few clicks.

Step 2:-  if you decide to use msi installer Check Whether your Operating System is 64 bit or 32 bit. You can right click My computer icon and check your System Type

windowsOS

Step 3: Now Download the files from the below Site. Choose the installer based on your operating system.

 

nodejsInstaller

Once after the download is over, execute the installer file which will complete the NODE JS.

Step 4: Alright now Node JS is installed Successfully. Now we need to create an Environment Variable that contains the Path of node_modules.

If everything is done correctly, open a command prompt and type the node command. if it works as shown in the below screenshot without any problem we are well set to start developing node JS application.

nodecmd

First Step with Node JS:-

Node JS provides several modules that helps us to mimic the webserver functionalities like tradional
webserver. To execute our first serverside javascript application follow the below steps.

Step 1:- Create a directory for placing your files. For the sake of this example i have created a directory called “nodelearning”,

Step 2:- Now create a new javascript file that acts as a web server. For this example i have created a new file named mynode.js

 

Code explanation:-

Node JS contains several modules, we can include them in our code. In the above example we are including
the http module. Once the http module is included in our script we can use the methods available in the module, we are using the createServer Method to create a webserver functionality by passing an anonymous function with request and response
arguments.

Inside the callback function we are Setting the Response Content Type and a Sample Text to print in the console.

Our WebServer listens to Port 8000

Step 3: Now open a command prompt and move to the c:/nodelearning directory. To Execute the mynode.js file
run the below command.

Now open a browser and execute the below localhost URL. A Plain Text content will be displayed

http://localhost:8000/

nodejsoutput

 

As I have come across node.js in my working environment I do have faced many challenges to achieve functionalities, I wrote this getting start tips to make node.js learning easier. If you have any queries or suggestions let me know by posting comments.

Leave a Reply