Getting Started with Node.js: A Practical Beginner's Guide

Learn the fundamentals of Node.js, install it, manage packages, and ship your first server with this practical guide for beginners.

By Santhor Team

What is Node.js?

Node.js is a fast, lightweight runtime that lets you run JavaScript on the server. It uses a non-blocking, event-driven architecture built on Google’s V8 engine, making it ideal for APIs, real-time apps, tooling, and command-line utilities.

Install Node.js

Install Node.js from the official download page or use a version manager like nvm to switch between versions easily.

  • Verify installation: run node -v and npm -v.

Your first program

  1. Create a folder: mkdir my-node-app && cd my-node-app
  2. Create index.js with: console.log("Hello, Node!")
  3. Run it: node index.js

Manage packages with npm

Initialize your project with npm init -y to create package.json.

  • Install a dependency: npm install express
  • Add a script in package.json: "scripts": { "start": "node index.js" }
  • Run your script: npm start

Learn more in the npm documentation.

Modules: CommonJS and ES Modules

  • CommonJS (default): const pkg = require("package")
  • ES Modules: add "type": "module" in package.json, then use import pkg from "package"

Asynchronous code made simple

  • Callbacks: traditional pattern, but can get hard to read.
  • Promises: doWork().then(...).catch(...)
  • Async/Await: const data = await fetch(url) inside an async function; it is clean and readable.

Build a tiny server with Express

  1. Install: npm install express
  2. Create server.js with: const express = require("express"); const app = express(); app.get("/", (req, res) => res.send("Hello from Express")); app.listen(3000, () => console.log("Server on http://localhost:3000"));
  3. Run: node server.js and open http://localhost:3000/.

See the Express documentation for routing, middleware, and more.

Debugging essentials

  • Auto-reload during development: node --watch index.js (Node 18+)
  • Inspector: node --inspect server.js then open chrome://inspect
  • Use console.log for quick checks and debugger statements for breakpoints.

Common pitfalls

  • Avoid blocking the event loop with heavy synchronous work; offload CPU-bound tasks to workers or queues.
  • Prefer npx package for one-off CLI tools instead of global installs.
  • Do not commit node_modules; add it to your .gitignore.

Next steps and resources

Keep practicing by building a small REST API, a CLI that automates a task, or a background worker that processes jobs.

More articles · Contact Santhor