Skip to main content

Command Palette

Search for a command to run...

What is Node.js ?

JavaScript on the Server Explained .

Updated
•4 min read•View as Markdown
What is Node.js ?

What Node.js is .

Node.js is a runtime environment that runs outside the browser. Initially, JavaScript could only run inside the browser and it was mainly used for building frontend applications.

  • To make JavaScript run outside the browser, a project was developed called Node.js. This means JavaScript would not only run inside the browser, but also outside the browser.

  • Because of this, today JavaScript is also used as a server-side language. For example, nowadays we build REST APIs using JavaScript.

  • Many big companies use Node.js today, such as :-

  • Uber, PayPal, Netflix and many large-scale startups also use it nowadays.

Why JavaScript was originally browser-only .

Initially, JavaScript was created only for browsers. The main purpose was to make websites interactive and handle frontend functionality inside the browser.

At that time, browsers needed a scripting language that could:-

  1. handle user interactions,

  2. and manipulate HTML and CSS

  3. Because of this, JavaScript was directly integrated into browsers using JavaScript engines.

But outside the browser, there was no environment available to execute JavaScript. That is why earlier JavaScript was browser-only and mainly used for frontend development.

How Node.js made JavaScript run on servers .

Initially, JavaScript could only run inside browsers because browsers had JavaScript engines to execute JavaScript code.

  • But the problem was that JavaScript could not run outside the browser, so it could not be used for backend or server-side development.

  • This problem was solved by Node.js.

  • Node.js provided a runtime environment with the help of the V8 JavaScript engine, which allowed JavaScript to run outside the browser.

  • Because of this, JavaScript could now handle server-side operations like:-

  1. creating servers,

  2. handling client requests,

  3. working with databases,

  4. file handling,

  5. and building REST APIs.

So basically, Node.js made JavaScript run on servers by providing an environment where JavaScript code could execute outside the browser.

V8 engine overview ( high level only ) .

The V8 engine is a JavaScript engine developed by Google. It is mainly responsible for executing JavaScript code.

  • Browsers like Google Chrome use the V8 engine to run JavaScript inside the browser. Node.js also uses the same V8 engine to run JavaScript outside the browser.

  • The main job of the V8 engine is to take JavaScript code and convert it into machine code so the system can understand and execute it faster.

Chrome uses it inside the browser.

Node.js uses it outside the browser.

Event-driven architecture idea .

Event-driven architecture means an application works based on events and responses to those events.

  • In this architecture, instead of continuously checking everything manually, the application listens for events. Whenever an event happens, a related function or callback gets executed to handle that event.

  • Node.js mainly follows an event-driven architecture because it works heavily with asynchronous operations.

  • For example, when a user sends a request, Node.js listens for that event and handles it without blocking the application.

  • Because of this approach, Node.js can efficiently manage multiple operations and requests together.

Real-world use cases of Node.js .

Node.js is used in many real-world applications because it is fast, scalable, and works very well with asynchronous operations and real-time communication.

  • Node.js is also heavily used in startups and scalable applications because it can manage many client requests efficiently with fewer resources.
💡
So with my above explanation i hope you understand what i learn and what's my thought process on What is Node.js ? JavaScript on the Server Explained .