Introduction to Node.js

Introduction

Hi all, how are you today? Today we will learn the basics of Node JS. Some of you might have already tried this. This article is for those that have never tried Node JS. I hope you will like it.

Please see this article in my blog. 

Background

Today one of my colleagues asked me “what is Node JS?”. I could manage a definition. But it might have not helped him much. So I thought of creating an article and send him the link for his reference. Hereby I am dedicating this article to him.

Node JS

  • Node JS is a run time environment for server-side and networking applications.
  • It is open-source.
  • It is cross-platform.
  • Node JS applications are written in pure JavaScript.
  • It can be run within Node.js environment on Windows, Linux, IBM and so on.

To start with

To start with Node JS, you need to go to https://nodejs.org/ and click on install.

 

Figure 1: Download

Now a .msi file will be downloaded to your system. Please run that once the downloading is over.

 

Figure 2: Installation

 

Figure 3: Installation Continue

Now I hope you have installed Node JS, so what is next? We need to test our node platform, right?

Testing Node JS

To check whether our Node JS is working, we can create a “Hello World” program in either of the following two ways:

  • Directly type a message into the command window.
  • Type the message in a JavaScript file and execute it in node.

Directly typing a message in a command window

Open your command window (press the Window key + R ), type cmd in the window. Now a window will be opened, you can type your commands into it.

 

Once you pointed out to your drive as shown in the image, type “node” and press Enter. Now you can type anything in your console using console.log. Then you will get the output as shown in the preceding image.

Now you may be thinking, why does it return an undefined error? Am I right?

It is because normally Node JS will display a return value for each command. As you all know, console.log does not return anything. So it is displaying "undefined".

Type the message in a JavaScript file and execute it in node

Create a JavaScript file manually. (To do so, open Notepad, type some content into it and save it with a .js extension. That is all.)

 

I typed the content as “console.log(‘Sibeesh passion welcomes you to the world of Node’);”.

Now you can execute that JavaScript file as follows.

 

Conclusion

I hope you will like this article. Please share me your valuable thoughts and comments. Your feedback is always welcomed.

Thanks in advance. Happy coding!

Up Next
    Ebook Download
    View all
    Learn
    View all