The VikiD Truth

Knowledge base / Computing / JavaScript

Javascript | Javascript kata |Node JS | Data Types | Variables | Control Flow | Scope and Environment | Objects | Functions | Events | Prototypal Inheritance | Three.js | 3DE Code Editor |

Node Js

Here is the truth about Node.js: it is JavaScript let out of the browser, with one big idea attached: never wait. Instead of a thread per connection that sits idle while the disk or network responds, Node runs your code on one thread and an event loop that picks up each result the moment it is ready.

What it is, in plain words

Node.js, created by Ryan Dahl in 2009, is a runtime: Google’s V8 JavaScript engine plus libuv, a C library for asynchronous file, network and timer I/O, plus a standard library (node:fs, node:http, node:crypto and so on). It comes with npm, the package manager and the largest package registry in the world.

Release rhythm: a new major every April and October; even-numbered majors become Long Term Support (LTS). In late 2026 that means Node 24 as the established LTS and Node 26 taking over as the newest LTS line; Node 20 reached end of life in April 2026. Recent Node gives you a lot built in that used to need packages:

Its competitors Deno and Bun are worth knowing about too; both run most Node code now.

Why it matters

An everyday analogy: one waiter, many tables

A traditional server hires one waiter per table, and most of them stand around while the kitchen cooks. Node has one very fast waiter. He takes an order, hands it to the kitchen (libuv), and goes straight to the next table. When a dish is ready, the kitchen rings a bell (an event) and he delivers it. One waiter, hundreds of tables, as long as nobody asks him to cook a ten-hour stew himself (CPU-heavy work, which belongs in worker_threads or another process).

A hands-on example

Install on Vikix with sudo xbps-install -S nodejs (it includes npm), or use a version manager like fnm or nvm if you need several versions. Then a modern server, using ES modules:

// server.mjs  -  run: node --watch server.mjs
import { createServer } from 'node:http';
import { readFile } from 'node:fs/promises';

const server = createServer(async (req, res) => {
  if (req.url === '/') {
    res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
    res.end('Hello from Vikix\n');
  } else if (req.url === '/os') {
    const release = await readFile('/proc/sys/kernel/osrelease', 'utf8');
    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ kernel: release.trim(), node: process.version }));
  } else {
    res.writeHead(404).end('Not found\n');
  }
});

server.listen(3000, '127.0.0.1', () => console.log('http://127.0.0.1:3000/'));
curl -s localhost:3000/os
# {"kernel":"6.12.10_1","node":"v24.x.x"}

Note the server sample further down this page sets res.status = 200, which does nothing. The property is res.statusCode, or use res.writeHead(200, headers) as here.

And a test, with no packages at all:

// sum.test.mjs  -  run: node --test
import { test } from 'node:test';
import assert from 'node:assert/strict';
test('adds', () => assert.equal(1 + 2, 3));

Common misconceptions

Connections

Notes

Official Node Documentation On older Ubuntu releases the command was nodejs, not node:

ln -s /usr/bin/nodejs /usr/bin/node

Mixu’s Node Book

Install NVM Manjaro Linux

Use Node Version Manager, NVM.

sudo pacman -S nvm

nvm install --lts
npm install "package name"
nvm uninstall --lts

Getting Started npm

npm install <package-name>

flags:

 --save-dev        saves to devDependencies
 --no-save         saves to Dependencies
 --save-optional   saves to optionalDependencies
 --no-optional

 -S --save
 -D --save-ve
 -O --save-optional
npm update
npm update <package-name>
npm install <package-name>@<version>

Running Tasks

npm run <task-name>

{
    "scripts":{
        "start-dev": "node lib/server-development"
        "start": "node lib/server-production"
    }
}
npm run start-dev

How do I find which version of V8 ships with a particular version of Node.js?

node -p process.versions.v8

http Server Sample

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.status = 200;
  res.setHeader('Content-Type','text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Development, Production Environment

{
    "scripts":{
        "start-dev": "node lib/server-development"
        "start": "node lib/server-production"
    }
}
in bash:

export NODE_ENV=production
NODE_ENV=production node app.js

if (process.env.NODE_ENV === 'development'){
  app.use(express.errorHandler({ dumpExecptions: true, showStack: true }));
}

if (process.env.NODE_ENV === 'production'){
  app.use(express.errorHandler());
}

if (['production', 'staging'].includes(process.env.NODE_ENV)){
  //
}

Last edited · 15 revisions

Tags: #Computing