Origin of NodeJs & its Version
NodeJs was created by Ryan Dahl in 2009 and the initial release was on 27th May 2009.
NPM (Node Package Manager) was created in 2009. The npm Registry is a public collection of packages of open-source code for Node.js
ExpressJs (It is a minimal and flexible Node.js web application framework) in 2010
Socket IO (It enables real time bi-directional communication between web clients and server) in 2010
Http2 introduces in 2017 this module provides an implementation of the HTTP/2 protocol
NodeJs 10 And then NodeJs 11 released in same year 2018
NodeJs v12 , V13 in 2019 , v14 , v15 in 2020 and latest v16 in 2021
Working of NodeJs
NodeJs uses “Single Threaded Event Loops” architecture which means it has only a single thread unlike multiple threads in other languages with the help of an event loop it manages the request and handles multiple concurrent clients.
Let’s start the operations for better understanding
NodeJs received the request and placed it into the Event Queue.
The Request enters the Event Loop and then executes further.
The Request is for Non-Blocking operations then it will send back the response after the operation is executed as a callback.
The Request is for Blocking operations, then it takes help from the Thread pool, those threads execute the operation and send back the response as a callback
Hope this makes sense to understand the architecture of NodeJS
Applications of NodeJs
Internet of Things
Single Page Applications
Real Time Collaboration Tools
Real Time Chats
Content Management system
NodeJs Application in Terminal (REPL Terminal)
ctrl + c − terminate the current command.
ctrl + c twice − terminate the Node REPL
ctrl + d − terminate the Node REPL
Up/Down Keys − see command history and modify previous commands
tab Keys − list of current commands
.help − list of all commands.
.break − exit from multiline expression.
.clear − exit from multiline expression.
.save filename − save the current Node REPL session to a file.
.load filename − load file content in current Node REPL session.
.exit to exit
NPM (Node Package Manager)
NPM is installed with NodeJs to check command npm -v
Further package install with npm command npm install
To install a package library globally use -g flag e.g. npm install -g
To add the package in dev dependency use –save flag e.g. npm install –save
To update a package use update keyword e.g. npm update
To uninstall a package use uninstall keyword e.g. npm uninstall
NVM (Node Version Manager)
nvm is version manager for NodeJs
nvm can help to switch between versions of nodes as per requirement.
To install nvm we have to get it from curl or wget
Require package http , fs , url and store in variables.
The fs module is used to interact with the file system
The http module is used to interact with the client and server.
http.createServer(requestListener) creates a server and it calls the requestListener whenever the user requests localhost:8000 listens on the next line on the port which is provided at server.listen(PORT).
Save index.js with server side code
Save index.html with client side code.
To run the code node index.js
Advantages of NodeJs
It is scalable for modern applications
It has huge community support.
Response Time is quick and Boosts Application performance.