How to create a super simple Hello World application in Node.js

Before you begin please install Node.js on your computer by following the instructions in our How to install Node.js lesson.

Once you have installed Node.js open up your text editor and create a file called server.js and fill it with the following code:

[codeblocks name=’codeblock_0′]

 

That’s it! You just create a Hello world application in Node.js.  But what is special about this application is that it is also a web application.  To test this first execute your Node.js script by typing in the following command in a terminal.

[codeblocks name=’codeblock_1′]

 

Then open up a browser and type the following address.

[codeblocks name=’codeblock_2′]

 

You should see a web page that displays “Hello World”!

3-21-2015 7-42-03 AM

 

What is special about this little script is that you have created not only a little program that run in a browser (a web application) but it also the web server (HTTP server) to support this application.  A web server is the engine that powers all websites on the Internet. Now you have one powering your program!

Leave a Comment