Back to all posts

5 Things You Probably Don't Know About Node.js

Sep 11, 2019 3 min read Engineering
5 Things You Probably Don't Know About Node.js

Introduction

A few days ago, I was reading an article about how Node.js child processes work and how the main process runs on a single core. After that, I started digging into the Node.js repo to learn more about its internal behavior.

These are the kinds of things you’ll never find in an online course. That’s why I’m writing this post.

Most learning resources on Node.js (especially online courses) focus on external packages rather than the runtime environment itself. Developers who only rely on those resources remain—hypothetically speaking—“average.”

Now, let’s explore some tricky aspects of Node.js that can level up your proficiency with this ecosystem.


1. The Call Stack is Part of the V8 Engine

Yes, it is. V8 uses the Call Stack as part of its architecture to keep track of function invocations.

So, what is the Call Stack? It’s a data structure that records all function calls. Every time we invoke a function, it takes a reference and pushes it to the stack, including nested calls and recursive calls.

callstack

From Philip Roberts: "What the heck is the event loop anyway" at JSConf EU.

It’s important to keep the Call Stack from being overloaded because there’s only one Call Stack per Node process. The stack only pops a function once it finishes execution and returns a value.


2. So, Is the Event Loop Inside V8 Too?

No. The event loop is provided by the libuv library, not V8.

Libuv is responsible for handling external events that rely on Node APIs. It picks tasks from event queues and pushes their callbacks into the Call Stack. Functions like setTimeout or fs.readFile belong to the Node API (via libuv), not to JavaScript itself.

The event loop decides what to execute next when the Call Stack is empty.

Node.js event loop architecture — Andranik Keshishyan

Node.js event loop architecture — Andranik Keshishyan


3. Why Does Node.js Exit?

When a Node program runs, it automatically starts the event loop and keeps iterating while there’s something to execute.

When both the Call Stack and the event loop have nothing left to do, the process exits.

However, Node keeps the process alive when you start something like a timer or an HTTP server.


4. Node External Dependencies

The Node.js environment depends on several external libraries for low-level operations in JavaScript. These include:

  • libuv
  • http-parser
  • c-ares
  • OpenSSL (crypto)
  • zlib

v8

All of these are external to Node. They have their own source code, their own licenses, and Node simply uses them.

It’s good to know this so we don’t unfairly blame everything on Node 😉.

📖 Read more about Node.js internal architecture


5. Node.js Could Be Used Without V8

Node.js requires a JavaScript VM to run the main process, but it doesn’t necessarily need V8.

V8 is Google’s open-source project, not originally built by the Node.js team. While uncommon, you could use other engines such as Chakra.

🔗 View Chakra repo on GitHub


6. Circular Module Dependencies Are Allowed

If two modules require each other, will it throw an error? No.

In these cases, Node.js will issue a warning. When the circular require loop starts, the first file won’t be fully loaded yet, so the second file will receive only a partial version of the first.

// module1.js
require("./module2");

// module2.js
require("./module1");

Conclusion

I hope you learned something new about Node.js internals and that this knowledge helps you in your journey with this amazing environment.

If you found these topics exciting, let me know in the comments!


Spotted a typo or have a suggestion? Send me a note.

Get new posts in your inbox

No spam. Just practical notes on engineering, cloud, and AI.