Node.js

Node.js is a server-side JavaScript runtime based on Chrome's V8 engine, renowned for its efficiency and performance in handling I/O-bound operations.

Utilizing JavaScript on both the client and server sides offers advantages such as code and library reuse, as well as reduced context switching for developers.

Even if you are not using it for backend development, you still need it for frontend tooling and package management.

Install Node.js

Use brew:

brew install node

If you want to use multiple versions of node, install nvm (node version manager), then use nvm to install and manager different versions of node.

npm

npm(node.js package manager) is a tool for installing, updating third part packages, or publishing your own packages.

It consists of a regitry and a command line tool, which is typically installed alongside the Node.js binary.

npm uses a configuration file called package.json, which keeps the track of your project's dependencies.

npm can also function as a task runner, with tasks defined in the package.json file for automating various workflows.

Many laughed at npm, but they clearly haven't tried package mangers from other languages.

Basic npm commands:

npm init

npm install --save <pkg>

npm Alternatives

npm is known for its slowness and high disk space usage. If that's a problem for you, try yarn or pnpm.

How non-blocking IO works

Node.js can handle multiple I/O operations, such as reading an HTTP request or executing a database query, concurrently without blocking program execution. Unlike other languages and runtimes, a single Node.js process can manage concurrent requests simultaneously, Making it a great choice for web applications.

When you initiate an I/O operation, Node.js does not wait for it to complete. Instead, it lets it run in the background and proceeds to execute other code. Once the I/O operation is complete, a callback function (or promise resolution) is invoked, allowing you to handle the result.

Underneath, Node.js leverages libuv, a cross-platform abstraction layer for asynchronous I/O, to handle these operations efficiently and in a non-blocking manner.

Alternatives

Node.js has been a dominant player in the JavaScript runtime landscape for years, but with the emergence of Deno and Bun, it’s facing some fresh competition.

Deno

Deno offers a more modern take, written in Rust, with built-in TypeScript support, Web-standard APIs and a secure environment by default. It is created by the original author of Node.js, it's like a Node.js 2.0 never adopted by the community.

Deno 2.0 is on the way, dressing the compability isssue with Node.js. A hard lesson learned.

Bun

Bun is a server-side JavaScript runtime built on JavaScriptCore, written in zig. It's extremely optimised for speed and performance.

Bun has also made a significant investment in developer experience, it comes with a comprehensive set of built-in tools and features including it's own package manager, bundler, test runner, sqlite support and more. Unlike Deno, it can be used a drop-in replacement for Node.js.

Node.js is Catching Up

Node.js has been evolving much faster recently, like TypeScript support, built-in sqlite, watch mode, test runner and many others are being borrowed from other runtimes.