Node.js hello world example

Getting Started with Node.js tutorial

Node.js is a Javascript framework that allows you to run javascript on server.

Learning by examples.

First of all make sure you have downloaded and installed node.js before getting started with this tutorial.

Hello word node.js application.

Code

How to  run above code

First save the file as  .js  file.Mine I saved as firstscript.js.

Open the command prompt and open the folder that contains the script file.

Once you have opened type “node filename.js”.

See below screenshot.

Node.js hello world example

After that ,your computer now becomes the server and its ready to serve your javascript  file.

Open your browser and type “localhost:8080

Below screen should appear with Hello world.

Running node.js in command line interface.

Some of the node.js results are better displayed on the command line.Using console.log() function,you can display the results in the command prompt.

Run code

Results.

running-node.js-in-console

If you a new node.js developer you will face one problem of restarting your script whenever you make changes.There are several options that you can use to automatically reload your script whenever you hit the save button.

Options to automatically reload node.js script whenever you make changes

1.Using nodemon

2.Using node-supervisor

About the Author: Eric K

Kenyan Developer and Blogger with Interests in Java,Javascript,Node.js, Wordpress, Android, PHP and Making Money Online. Solving world problems through programming is my passion. Hire me: Email : kawi3462@gmail.com