What is Node.js 

Node.js is an open source cross-platform for developing server-side and networking applications. It provides runtime environment and uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Moreover applications are written in JavaScript and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux moreover its package ecosystem, npm is the largest ecosystem of open source libraries in the world.

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Historically, JavaScript was used primarily for client-side scripting, in which scripts written in JavaScript are embedded in a web page’s HTML to be run client-side by a JavaScript engine in the user’s web browser. It enables JavaScript to be used for server-side scripting and runs scripts server-side to produce dynamic web page content before the page is sent to the user’s web browser.


Previously javascript code is in working on the client side(front end) only. But with the power of node.js, we can now play with it on the server side (backend) also to generate the dynamic content. Node.js is actually based on the event loop programming model. It repeatedly waits for events and then runs any event handlers subscribed to those events and the event loop runs in a single thread.

Events can be:

1) A new HTTP request coming our way
2) Timer wait is complete
3) Next chunk of data is ready to be written to the file

Due to this process, multiple requests are handled concurrently by a single Node.js process. As long as these event handlers are small and wait for yet more events themselves everything works out nicely and no Javascript code is ever executed in parallel, all of this runs in a single thread.

Why node is single threaded?

Node.Js was built with the intention of supporting asynchronous operations and the fact is that the asynchronous operations have better performance and scalability when they are single-threaded over multi-threaded. This is the reason the Node.Js is single threaded.

Features of Node.js

1) Server Side java Script
2) Versatile
3) High Reliability
4) Asynchronous
5) Single Threaded
6) Run Anywhere
7) No Buffering
8) Easy Integration with JS Stacks
9) Speedy Execution

Top websites powered by Node.js

1) https://www.paypal.com
2) https://www.groupon.com
3) https://www.wsj.com
4) https://www.shutterstock.com
5) https://www.opencare.com

For more info visit: https://codebrahma.com/top-10-sites-powered-by-node-js/ 


For Linux follow the guide.

For Windows download the installer.

To check if nodejs is installed successfully, Open command prompt and type

node -v

What is NPM 

npm is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js. It consists of a command line client also called npm, and an online database of public packages called the npm registry.



Set up node.js application

Before create a node.js application we need to install express framework using npm command. ( Express is a lightweight and easy to use Node.js framework that helps to create and manage our apllication into MVC architecture.Express provides a robust set of features to develop mobile and web applications)



To install express run 

npm install express -g

The above command will install express globally on your machine. then type

npm install express-generator -g

It will install the express generator globally on your machine. After that to create the skeleton of node app just type 

express projectName

This will create the node.js skelton with name projectName, where project name is the name of your app skeleton. After that just go in the app structure and install the app dependencies by 

cd projectName
npm install

It will create the node modules folder where it install all the dependencies, after that just type npm start command to start the server and check it works or not. To check its proper working after run the start command just open any browser and type localhost:3000 to check the server is listening or not (3000 is the default port uses by it).

npm start

Now open any browser and hit localhost:3000

Leave Comment

Your email address will not be published. Required fields are marked *