What is NodeJS, exactly?

Vishwalakpriya
5 min readMay 15, 2022

What is Node.js?

Node.js is a cross-platform open-source JavaScript runtime environment that allows JavaScript code to be executed outside of a web browser. Let’s look at what each of these terms means.

  • Open-source: Node.js has a healthy community of contributors who work to keep the platform feature-rich and up to date.
  • Cross-platform: Applications written in Node.js can be run on Windows, macOS, or Linux.
  • Runtime environment: Node.js is built on Google Chrome’s V8 engine and includes everything you need to run JavaScript outside of the browser.

A Node.js application executes in a single process. While this has advantages and disadvantages, the asynchronous nature of Node.js allows it to handle multiple server requests without the hassle of managing threads.

Node.js makes use of V8, Google’s open-source, high-performance JavaScript and WebAssembly engine. This gives Node.js a competitive advantage over other frameworks. On npm, there are over 1,000,000 open-source packages for Node.js. This has significantly aided Node.js’s growth. It is frequently easier to use a package than to write code from scratch. The use of packages has greatly improved code reusability.

Why Node.js?

As a beginner, deciding which web framework to learn first can be difficult. Surprisingly, no definitive answer exists. We’ve listed a few reasons why Node.js is a good place to start below.

  • Node.js is ideal for data-intensive applications such as streaming and real-time apps, which is why Netflix and Uber use it.
  • Node.js makes it simple for front-end developers who are already familiar with JavaScript to begin developing the back-end.
  • Node.js, in contrast to Ruby on Rails, is very lightweight and uses fewer resources.

How NodeJS works?

While working with the request, Node.js accepts requests from clients and sends responses. They are handled by a single thread in node.js. Threads are used by Node.js to handle I/O operations and requests. A thread is a set of instructions for the server to execute. It runs in parallel on the server in order to provide data to multiple clients. Node.js is a single-threaded event loop language. With a single thread, it can handle multiple requests without blocking it for one.

Node.js is based on two concepts.

  • Asynchronous
  • I/O without blocking

Asynchronous: It means that a callback function is being executed. A callback function will be executed as soon as we receive a response from the other server or database. Because of the node, callback functions are called as soon as some work is completed. The architecture of js is event-driven.

I/O without blocking: Working with multiple requests without blocking the thread for a single request is known as non-blocking i/o. External systems such as files and databases interact with I/O.

To implement the system’s concept of handling the request node into action. The Libuv concept is used by js.

Libuv is a C-based open-source library. It focuses heavily on asynchronous and I/O, allowing nodes to access the underlying computer operating system, file system, and networking. Libuv implements two very important features of node.js.

  • Event loop
  • Thread pool

Event loop: The event loop is composed of a single thread that is responsible for simple tasks such as callback execution and network I/O. The heart of node.js is the EventLoop. The event loop starts running as soon as we start our node application. The event loop is where the majority of the work is done.

Nodejs use event-driven-architecture.

  • Events are emitted.
  • Event loop picks them up.
  • Callbacks are called.

Event queue: The thread immediately places the request into an event queue after it is sent. It’s called an event queue. The event loop is an infinite loop that receives and processes requests indefinitely. It checks the queue and waits indefinitely for the incoming request.

Thread pool: Though node.js is single-threaded, it maintains an internal thread pool. Non-blocking requests are processed in an event loop, but blocking requests are checked for available threads in a thread pool, a thread is assigned to the client’s request, which is then processed and returned to the event loop, and a response is sent to the respective client.

V8 engine in Node.js

What is a V8 Engine?

Google V8 is a C++-based open-source JavaScript engine. It was created in 2008 for Google Chrome and Chromium-based browsers, but it was later used to create Node.js for server-side coding. In reality, the V8 engine is used by JSON-based No-SQL databases such as Couchbase and the widely used MongoDB. V8 is also the foundation for Electron, a popular desktop application framework, and Demo, the most recent server-side runtime environment.

Why Node.js Is So Popular?

Aside from being effective, Node.js is popular due to its large, active, open-source, JavaScript-based ecosystem. Furthermore, it does not significantly impair compatibility between versions. We’ve listed below a few reasons why Node.js is popular.

  • It is JavaScript Everywhere(it uses JavaScript as its main language to build web applications)
  • It’s lightning Fast(Node.js is primarily a JavaScript runtime that is powered by V8)
  • It is Lightweight(Node.js uses a basic event-driven architecture)
  • A Single Language for All Layers(language re-use)
  • High Performance(PayPal uses Node.js)
  • It can be Hosted Anywhere(Google, Amazon AWS, Heroku, Microsoft IIS, Microsoft Azure)
  • It is Easy to Modify and Maintain

Conclusion

Node.js is currently popular. It offers numerous opportunities for developers to create highly robust and scalable web applications. So it’s worth a shot before it’s too late. This is, after all, the world of web development!

I hope this introduction to Node.js will help you to understand some of its concepts. For some more great things!, from Vishwalakpriya

--

--