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:

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();
}).listen(8888);

 

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.

node server.js

 

Then open up a browser and type the following address.

http://localhost:8888/

 

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!

3

32 thoughts on “How to create a super simple Hello World application in Node.js

  1. Pingback: generic cialis
  2. Pingback: generic cialis
  3. Pingback: cialis online
  4. Pingback: Us pharmacy viagra
  5. Pingback: Get viagra fast
  6. Pingback: buy albuterol
  7. Pingback: ciprofloxacin hcl
  8. Pingback: online cialis
  9. Pingback: canadian cialis
  10. Pingback: cialis 5 mg
  11. Pingback: cheap viagra
  12. Pingback: viagra for sale
  13. Pingback: cheap viagra
  14. Pingback: amoxilin
  15. Pingback: cialis mastercard
  16. Pingback: levitra 20mg
  17. Pingback: levitra cost
  18. Pingback: generic sildenafil
  19. Pingback: casinos online

Leave a Reply