Node.js Overview & Environment Setup

What Node.js is, the V8 engine and Libuv, CommonJS vs ESM, nvm version management, npm and package.json, and writing your first server.

BeginnerUpdated 2026-10-3066K views

What is Node.js

Node.js runs the V8 JavaScript engine (the same one in Chrome) outside the browser, with Libuv providing the event loop, thread pool and async IO. It lets frontend developers write backends in JavaScript, and its npm registry is the largest package ecosystem in the world.

  • Best for: REST APIs, real-time apps (WebSocket, chat), BFF layers, tooling and CLIs.
  • Think twice for: CPU-heavy computation (video encoding, ML inference) — it blocks the event loop.

Version Management with nvm

# 安装 nvm 后
nvm install 22         # 安装 LTS
nvm use 22
node -v                # v22.x
npm -v

# 国内镜像加速
npm config set registry https://registry.npmmirror.com

npm and package.json

mkdir app && cd app
npm init -y                    # 生成 package.json
npm install express             # 依赖写入 dependencies
npm install --save-dev jest    # 开发依赖 devDependencies
npm install                    # 按 package-lock.json 还原
npm run dev                    # 执行 scripts.dev

# 锁定语义化版本:
# ^1.2.3 允许 1.x.x
# ~1.2.3 允许 1.2.x
# 1.2.3  精确版本
Commit package-lock.json so every machine and CI installs byte-identical versions. npm ci is the strict, faster install for CI.

CommonJS vs ESM

// CommonJS(默认)
const fs = require('fs');
exports.hello = function () { return 'hi'; };

// ESM:package.json 加 "type": "module"
import fs from 'fs';
export function hello() { return 'hi'; }

// 动态 import(两者皆可)
const { hello } = await import('./lib.js');

Modern projects prefer ESM (top-level await, better static analysis); many legacy packages remain CommonJS. Both work in Node 22, but you cannot mix require and import in the same file freely.

Your First Server

import http from 'http';

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ message: 'Hello, BackendWiki' }));
});

server.listen(3000, () => console.log('listening on 3000'));
Node projects standardize on eslint plus prettier: lint catches undefined variables and unused code, prettier keeps formatting consistent, and both run on save and in CI.

Friends & Partners