Learning Node.js šŸ¤© šŸ¤© šŸ¤©

Sam Lesser
6 min readMar 27, 2021
How does one get good at Node.js? šŸ‘Øā€šŸ’» šŸ§‘ā€šŸ’» šŸ‘©ā€šŸ’»

Introduction

Hello Fellow readers. Recently Iā€™ve taken a break from LeetCode explanations and wanted to share with you a new technology Iā€™ve been learning in my spare time. In this blog, I will give you a general understanding of Node.jsā€™ Runtime environment, its benefits, and how to set Node.js on VScode.

I think the best way to understand something is to ask informal questions. It gives us a really personal way to grasp the material. Questions will help me flesh out the topic. We want to understand the general idea here, so we can explain(most importantly in your own words) and justify why itā€™s worth your time to learn it! So grab a coffee or tea, put on some chill ambient music, and letā€™s dive into a causal read about Node.js.

What is Node.js?

Note on runtime: a runtime environment is the environment in which a program or application is executed. It's the hardware and software infrastructure that supports the running of a particular codebase in real time.

Ryan Dahl initially wrote Node.js in 2009. The idea being, you could use Javascript to write scalable network applications. He also wanted to create real-time websites(super responsive and reactive websites) with push capabilities(a form of communication). We use these technologies today, which make for a much better user experience. Node.js also has a great advantage for developers as they would only need to learn one language for full-stack development.

Itā€™s important to note that it wasnā€™t the first runtime environment(sandbox where code is executed) to attempt this. That credit goes to Netscape and its LiveWire Pro Web about 13 years ago. Like most things in science, people build off each other's successes and failures, advancing the concept in an objective fashion. We see this with Dahlā€™s Node.js.

Yet Node.jsā€™s success is also credited to the impressive implementation of Googleā€™s V8 engine. This Javascript & Web Assembly Engine in C++ was a much-needed improvement. Basically, Javascript got a huge upgrade in back-end development. Allowing it to tap into machine-level code and optimize tasks.

The big takeaway here is being you have a Non-blocking(itā€™s a multi-tasker, little or no waiting) and Event-driven (always listening to the server looking and reacting) ā€œphilosophyā€ when dealing with back-end problems. This creates an incredible user experience, so dang good you donā€™t even notice it unless something breaks!

How it works

Notice how Node.js doesnā€™t wait?
Pretty cool huh, see the divide and conquer approach here?

Oh boy, letā€™s try to boil this down(Not an expert, just a huge dorky fanboy herešŸ¤“ ).

Node.js is an excellent listener. It does this by using an Event Loop. This loop runs infinitely, constantly listening to your created server. If it breaks, Node.js stops working.

Node.js is also really good at dividing tasks that take a lot of time or are very expensive in computation(code that slows it down). It does this by listening to callback functions or functions that fire off based on certain circumstances(common in computer code, think like a specialized lego piece).

The Event loop runs in phases. Yet can jump backward if it needs to resolve any outstanding tasks that need to be done. Each phase is meant to divide its given tasks efficiently for better performance and user experience. Timers, Pending Callbacks, Poll, Check, and Close Callbacks are all phases that it works through. Without getting too much into detail, I will say that itā€™s a very meticulous process, which accounts for alot of complicated factors in your backend. Donā€™t think of it as Node.js magic but rather a complicated dance move that dots all the ā€œiā€s and crosses all the ā€œtā€s.

There is also a component known as the Worker Pool. This component does most of the heavy lifting, such as traversing through your file system or resolving complex and time-consuming code. The worker pool can also tap into additional threads from your CPU, thanks to the C++ magic from the V8 engine. This can give it the additional strength it needs to tear through all the work that ends to get done. When it finishes this code, it talks to the Event Loop with a callback function. Making work delegation and execution a team effort!

I like to think of lazy(Event Loop) vs. hardworking mindset(Worker Pool) workers. Lazy folks like to do many easy tasks. Completing multiple tasks feels satisfying, while hard-working folks focus all efforts on whatā€™s in front of them and seek the challenge. They both do work, but how we manage them creates a level of productivity thatā€™s impressive. Node.js is that manager.

The Event Loop and the Worker Pool both fire up automatically in your Node.js code. This isnā€™t something you deal with when you work with Node.js. Itā€™s a broad-strokes šŸŽØ šŸ–Œ explanation of whatā€™s going on under the hood.

Why use Node.js?

Cool Graphic šŸ˜Ž

Everyone learns Javascript at some point in their developer career path. Chances are, youā€™ll make a few web-based projects or even smartphone applications. Youā€™ll want to impress people with projects like SPAs(Single Page Application) or Chat Apps which are great to build with Node.js.

Apps tend to be front-end heavy, and youā€™ll do alot of the work in the front-end as you most likely building for user experience. The more features you add, the more front-end work youā€™ll need to do. Node.js is a good choice in this environment, letting you focus on those important features.

Node.js is also pretty good at scalability. Itā€™s baked into the design, thanks to its philosophy or paradigm. Thatā€™s important in tech as you build your user base. You never know if your next project becomes the new Facebook; having this already setup makes your life much easier!

Node.js offers an easier learning path as you wonā€™t need to take time learning a new language to get your project off the ground. The Combination of Node.js + Express(Web framework for Node.js) is a real great way to understand whatā€™s going on server-side with your application.

Coming from a Ruby on Rails background, alot of the back-end technical stuff gets abstracted out(simplified for user experience), which is nice for the day-to-day coder. Yet you donā€™t get an appreciation or deeper understanding of back-end setup like you would with Node.js. Youā€™ll build alot more on your own, which makes it a great experience for the more seasoned developer.

Companies building with Node.js- Netflix- PayPal- Trello- Capital One- LinkedIn- Yahoo- Mozilla- Uber

Setup

Have I sold you yet on learning Node.js? Awesome, please allow me to walk you through an install. Chances are you may already have Node.js locally, thanks to NPM. Letā€™s check your IDE and see what the latest version is. I use VScode; itā€™s a pretty common IDE for developers. If you are interested, click on the link below and install before you go through these instructions.

check in your terminalnode -v

If it isnā€™t the latest version, letā€™s download it from the Node.js website. Click on the latest version based on the current platform your running (OS or Windows)

https://nodejs.org/en/

Now follow the installer's guide. After that, letā€™s recheck our terminal to make sure everything is working as it should. We want to make sure we got the right version. We also want to make sure the Node.js is working by entering its baked-in REPL(testing environment).

In terminal:
node -v
REPL:
node

Congrats, you got a Node.js setup. Pretty easy, right?

Conclusion

Big disclaimer here, not an expert. Just writing about the broad strokes and greatest hits on Node.js. If you want a comprehensive understanding of this topic, please check the links section below for additional resources. It never hurts to read from multiple resources, right ;).

Node.js is awesome for App development. I encourage you to learn more using online documents or courses. Node.js is a universe in itself and really worth taking the time to build, learn, and grow within it as a professional.

Check out these Hot Links:

More on Node.js: https://en.wikipedia.org/wiki/Node.js 
Runtime Enviroment/Runtime System: https://en.wikipedia.org/wiki/Runtime_system
Node.js here
:https://nodejs.org/en/
Grab Vscode here: https://code.visualstudio.com/

--

--

Sam Lesser

Career Changer, Software Engineer & Web Developer