Node.js is a JavaScript runtime built on Chrome's V8 engine that enables JavaScript to run on the server, outside of the browser. This post covers Node.js fundamentals including the event loop and non-blocking I/O model that makes it performant, the module system, npm package management, and the key differences between running JavaScript in Node.js vs the browser.
Installing Node.js
Choose your operating system and LTS version :
https://nodejs.org/en/download
Node.js Release Cycle: https://github.com/nodejs/release#release-schedule
Node VS JavaScript
How is node different than Javascript? We know that JavaScript is a programming language, and anytime you want to run some Javascript code or a file on your computer, you send it to a Javascript engine like Chrome's V8. But also potentially others like Firefox is Spider Monkey Engine or Chakra, which was used in early versions of Microsoft's Edge browser.
This engine then converts those Javascript Instructions to those that the hardware on your computer or phone understands. Nodejs is a way of running JavaScript instructions on your computer outside of the web browser. Node only became possible because the Chrome team from Google made the V8 engine open source. Ryan Dole took advantage of this release by the Chrome team and created the node runtime around the V8 Javascript Engine.
Now, node contains a lot more than just V8, but prior to Node javascript could only be run in a browser and not standalone because browsers were the only ones who had JavaScript engines like V8. Node was built so that we could run Javascript anywhere, including your computer, but also your phone. Even to control robots whenever you run JavaScript outside of the browser. Chances are you're running node.
Now, there are other JS runtimes available like Deno, which uses the V8 engine similar to Node, and there are even ways of running Node.js using other JavaScript engines.
The global Object
Why do we have global in Node? Why do we have a window in the browser? In the browser, we tend to deal with HTML and browsing documents instead of processes like Node script or a Node server that are running on your system. And so on the browser, we have things that help us interact with our browsing history and figure out our location, the current address or URL our browser is pointed to, and there's navigator object, which give us access to data about the browser that we're currently using.
These things don't make very much sense in Node, but on the other hand, we have access to things like the arguments that were passed into our process.
Node.js
- global
- process
- module
- __filename
- require()
Backend Vs Frontend
How is Node most often used? We can use it for scripts that do things on our computer. For example, to read and write files. But in the majority of cases, we use Node to create servers to build web and mobile applications that connect to databases and provide user data and things like videos, photos and other content. And our servers also provide security features like allowing users to login.

Synchronous vs Asynchronous
What does asynchronous mean in programming?
Asynchronous is often described as the opposite of synchronous, where synchronous means code that runs line by line in sequence. So, asynchronous code is code that doesn't necessarily run line by line.
Non-Blocking Input & Output
What is a non-blocking function?
Blocking code executes synchronously with both node and your browser have a built-in JSON.stringify function that blocks until completion and any commands after it only executes once it's done doing what it does, which is that it takes a javascript object and returns the string representation of that object.
But non-blocking functions like setTimeout, execute in the background or even in parallel with the rest of our code. The one-second timer is running, while the next line of code is already executing.
Comparing Node with PHP and Python
Why are we learning Node.js differently than languages like PHP and Python? Java, C and C++ is that those languages support multi-threaded. But PHP and Python are both high-level, easy-to-use, single-threaded programming languages. Just like Javascript.
So, what's the difference?
If we think back to back in the day, 20 years ago. When it came to the Web, PHP and Python followed a more traditional model where they needed a web server, something like Apache to handle multiple requests coming in. Apache was a big hit and it had a lot going for it, including that it was free and open source.

With this web server, any request to our server, asking for some data. Was blocking, so we would handle it as a new thread because each thread would be blocked by our blocking PHP or Python code. We would have to spawn another thread in Apache for the next request and the next request after that and so on. Each client taking to our server would get its own thread. This means that our server needed a lot of threads with a lot of resources being used by those threads. The server would only be able to handle as many connections as it could threats, which made building sites that serve millions of users quite difficult and expensive. Serving a site like Facebook or Google that gets a lot of traffic. Your server would crash pretty quickly.

In 2009, Node became popular because of its model of non-blocking IO taking in all of these requests. In the Node.JS model, we take the request into the Javascript engine. Remember that it's mostly single threaded and for each request coming in, we quickly pass it off from the engine to be handled by LibUV which queues it up on the event loop, even though your Javascript code runs in a single thread, Node allows you to handle thousands of concurrent requests by delegating or passing off the majority of the work, it passes this work off specifically to the multiple threads in the thread pool and wherever possible, skipping over the thread pool and talking directly to your operating system because your operating system is already multithreaded. This work can be done without blocking your server. All of this happens in the Nodejs process.

There's no need for an additional web server like Apache to create thousands of threads. Looking back on things, the PHP model worked pretty well. But for many connections at the same time, the NodeJs IO model worked really well. Now looking forward, things these days are changing, and the concept of non-blocking input/output is being used more and more.
Python, for example, has integrated support for running an events loop out of the box, bringing it a step closer to Node.
Why use Modules?
A module is just like a box that contains some code that is dedicated to doing one thing well. So, we label the box with a name like http.js, which corresponds to the name of our module. We combine these modules with each other to create more complex structures, which all together make up our program. That relies on all of these modules working together to achieve our goal.
We might want to use modules for three main reasons:
- Reuse existing code.
- Organize your code.
- Expose only what will be used.
Frequently Asked Questions
What is Node.js?
Node.js is an open-source, cross-platform JavaScript runtime environment that executes JavaScript code outside a web browser using the V8 engine, enabling developers to use JavaScript for server-side programming, build tools, and command-line applications.
What is the Node.js event loop?
The Node.js event loop is the mechanism that enables non-blocking I/O operations — it allows Node.js to handle thousands of concurrent connections on a single thread by offloading operations like file reads and network requests to the OS and processing callbacks when they complete.

