NashTech Insights

Table of Contents
node.js overview

Today, we cannot deny the popularity of Node.js, which exists in all fields: Micro-services, IoT (automation), Cross Platform (electron.js), etc. Besides, it is a helpful tool in modern front-end websites (Server Side Rendering, build tool – web pack, etc.). So, today’s article will briefly introduce Node.js and how to install and use this language.

What is Node.js?

Introduce

Node.js is a cross-platform javascript runtime. The development team used Chrome’s V8 JavaScript engine to build it with the performance mindset. And it will compile JavaScript directly to native machine code.
When talking about that, we should talk about the following:

  • Event-based
  • Non-blocking
  • Asynchronous I/O runtime

How to install Node.js?

To manage multiple versions of Node.js, we will install nvm

Windows

  • Uninstall any existing versions of Node.js.
  • Delete any existing Node.js installation directories (such as C:\Program Files\nodejs)
  • Delete the existing npm install location (such as C:\Users\<user>\AppData\Roaming\npm)
  • After this, download and run the latest stable installer, and you should be ready!

MacOS/Linux

with cURL command

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash

with Wget command

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash

This will clone the nvm repository to ~/.nvm and make the required changes to your bash profile so that nvm is available anywhere in your terminal.

Using nvm

Install node version

nvm install 12.16

List all nodes installed.

nvm list

Use specific node version

nvm use 12.16.2

Check it

node -v
npm -v

Quick view for Node.js

Node.js allow running JavaScript on the Server, but that’s not new. Coming back to 1994, Netscape is the first attempt to do that. However, Node.js is the first implementation to gain any real traction. That provides some unique benefits compared to traditional languages.

Execute Model

Node.js is single-threaded, but in the background, it uses multiple threads to execute asynchronous code with the help of the libuv library.
It’s also event-driven, which means that everything that happens in Node is in reaction to an event.

  • A new request comes in (one kind of event), and the server will start processing it.
  • If it encounters a blocking I/O operation, it will register a callback before processing the next event.
  • When the I/O operation has finished (another kind of event), the server will execute the callback and continue working on the original request.
Node.js handle processes with libuv (Event Loop)
Node.js handle processes with libuv (Event Loop)

What kind of Apps is Node.js suited to?

Generally, it can use in any business domain. But to be relevant to the strength of it, we need to focus on some aspects.

  • Real-time interaction or Collaboration (chat, codeshare)
  • API handles lots of requests that are
    • I/O driven (such as those needing to perform operations on a database)
    • Sites involving data streaming (Node makes it possible to process files while they’re still being uploaded)
  • Simple CRUD app. (There are a lot of frameworks that support us in building CRUD app)

Besides that, we can use it in other use cases:

Trần Minh

Trần Minh

I'm a solution architect at NashTech. I live and work with the quote, "Nothing is impossible; Just how to do that!". When facing problems, we can solve them by building them all from scratch or finding existing solutions and making them one. Technically, we don't have right or wrong in the choice. Instead, we choose which solutions or approaches based on input factors. Solving problems and finding reasonable solutions to reach business requirements is my favorite.

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

%d bloggers like this: