What is Node-JS : Node JS is an open-source server side runtime environment built on Chrome’s V8 JavaScript engine. It provides an event driven, non-blocking (asynchronous) I/O and cross-platform runtime environment for building highly scalable server-side application using JavaScript.
Node.js can be used to build different types of applications such as command line application, web application, real-time chat application, REST API server etc. However, it is mainly used to build network programs like web servers, similar to PHP, Java, or ASP.NET.
what makes Node.js different I am going to explain.
- It’s easy to get started and can be used for prototyping and agile development
- It provide fast and highly scalable services
- It uses JavaScript everywhere so it’s easy for a JavaScript programmer to build back-end services using Node.js
- Source code more cleaner and consistent.
- Large ecosystem for open source library.
- It has Asynchronous or Non blocking nature.
The Node.js run-time environment includes everything you need to execute a program written in JavaScript. Node.js came into existence when the original developers of JavaScript extended it from something you could only run in the browser to something you could run on your machine as a standalone application.
- let’s understand the other two lines so we can find out why Node.js is so popular.
- I/O refers to input/output. It can be anything ranging from reading/writing local files to making an HTTP request to an API.
- I/O takes time and hence blocks other functions.
Blocking I/O
In the blocking method, user2’s data request is not initiated until user1’s data is printed to the screen.
If this was a web server, we would have to start a new thread for every new user. But JavaScript is single-threaded (not really, but it has a single-threaded event loop, which we’ll discuss a bit later). So this would make JavaScript not very well suited for multi-threaded tasks.
Non-blocking I/O
On the other hand, using a non-blocking request, you can initiate a data request for user2 without waiting for the response to the request for user1. You can initiate both requests in parallel.
This non-blocking I/O eliminates the need for multi-threading since the server can handle multiple requests at the same time.
What is NPM – npm (Node package manager) has packages you can use in your apps to make your development faster and efficient.
Advantages
- Easy Scalability:
- Real time web apps:
- Fast Suite:
- Easy to learn and code:
- Advantage of Caching:
- Data Streaming:
- Hosting: Corporate Support:
Discover more from CODE t!ps
Subscribe to get the latest posts sent to your email.