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:
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.
Then open up a browser and type the following address.
You should see a web page that displays “Hello World”!
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!