Learn Node With Yasir (LNWY): Part 1

Yasir Gaji
2 min readJan 4, 2024

--

LNWY Part 1 Image By Yasir Gaji
First LNWY Image By Yasir Gaji

First of all, shout out to Ryan Dhal for creating a god-tier tool and the OpenJS Foundation for making it better.

Origin

NodeJS is a C++ application built on the Chrome V8 javascript engine and as you probably know or don’t know for a computer to execute high-level codes it uses interpreters, compilers, transpilers, and assemblers(occasionally…lol), well V8 is a type of interpreter that also optimizes run time to make the execution faster.

Process

Simply put, It works with V8 and decides which function should executed when, where, and how simultaneously, but…

NodeJS is a server-side javascript runtime environment which means it would operate on the computer operating system as opposed to running on the web browser or mobile by deciding when and which javascript file should be executed by parsing it to the V8 engine using two applications:
A script processor and A REPL.

A script processor invokes “node” before a script that's parsed to it and is about to be executed for instance node index.js but it’s a bit deeper than that; when the script processor invokes it first initializes an event loop and then processes the initial scripts in the JS file then finally processes the event loop initialized earlier.

As you know or don’t know Javascript is a language that’s capable of recalling/including both synchronous and asynchronous functions/behaviors to be executed hence why the event loop is an infinitely repeating task that continually checks if there’s anything new for Node JS to do before executing(checking the new function did not trigger an initial function), But only non-blocking tasks can be added to the to-do-list of the node invocation.

But How?

At this point, I’m guessing just like me you are wondering how Node is capable of all this magic, like really how can it run an entire application split across so many files? It seems counterintuitive one might say, because when we invoke just one file it then runs an entire application.

Well, this is as a result of the Node Module System. 🙃

More on that in the next part. ✌🏽

Notes

Interpreters: These compile and execute source codes in real-time without leaving behind any program.

Compilers: These turn source codes into machine code which in turn returns an executable file.

Transpilers: These generate more source codes of different types from an existing source code.

We have other similar engines like V8 which are JavascriptCore by Apple, Spider Monkey by Modzilla, Chakra by Microsoft, and many more.

REPL means Read Eval Print Loop.

Non-Blocking: these are tasks that can’t be executed synchronously like invoked callback functions, timeouts, and intervals.

Conclusion

I expect questions for clarification. Kindly criticize and make corrections as well. Share, Thank you.

--

--