Introduction to Nodejs

A short intro with Hello world !

Introduction to Nodejs

What is Nodejs ?

Nodejs is an open-source and cross-platform runtime environment for JavaScript. Built on V8 engine, it is capable of executing JavaScript code outside a browser. It is designed for building scalable, server-side network applications using an event-driven and non-blocking/asynchronous model .


Installation

Nodejs can be downloaded from it's website, following corresponding OS guide.

Use the following command to check for successful installation, which will return node's version .

node -v

Packages and Managers

Packages are the external libraries or modules which are used to enhance functionalities in our project. These packages can be distributed, installed, modified or removed using various package managers.

npm is the default package manager for Nodejs. However, there are popular alternatives such as yarn , pnpm and bun .


Initialize a project

A project can be initialized and linked with Nodejs using the following command .

npm init

After running this command in terminal, a configuration file , package.json will be created that contains metadata of our project. We have to provide information such as the project name, version, description, entry point, test command, git repository, keywords, author and license or press Enter to accept the default values.


Hello World in Nodejs

  • Create your project folder.

  • Initialize the project as stated above.

  • Create index.js file in your project.

  • Add the following code :

            console.log("Hello world !")
    
  • Finally, run the file using Nodejs :

            node index.js
    

What did you find ?

Well, after executing the command above, we will be able to see output Hello World ! in terminal. This is possible with the help of Nodejs !