Node.js lets you run JavaScript outside the browser, mainly to build servers, APIs, command-line tools and build tooling. Install the current LTS version from nodejs.org, create a project with npm init -y, write a server with the built-in node:http module or the Express framework, and run it with node server.js.
Note: Frameworks release often — confirm version-specific details in the official docs.
This Node.js tutorial starts with the big idea: Node.js lets you use JavaScript — the language you may already know from the browser — to build servers, APIs and tools. For many web developers, it is the most natural way to move from front end into back end, because the syntax is familiar and the npm ecosystem has a package for almost everything.
This tutorial gets you running a server and a small API, then shows you how to structure a project so it stays manageable as it grows.
Install Node.js
Download the LTS (long-term support) installer from nodejs.org, or use a version manager such as nvm, fnm or Volta to switch between versions. Check it works:

node --version
npm --version
Node.js tutorial: your first server
// server.mjs
import { createServer } from "node:http";
const server = createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("Hello from Node.js");
});
server.listen(3000, () => console.log("Running on http://localhost:3000"));
Run it with node server.mjs, or node --watch server.mjs to restart automatically when files change.
npm and packages
npm init -y # create package.json
npm install express # add a dependency
npm install -D eslint # add a development dependency
Add "type": "module" to package.json to use import syntax in .js files.

Build a simple REST API with Express
import express from "express";
const app = express();
app.use(express.json());
const posts = [{ id: 1, title: "Hello Node" }];
app.get("/api/posts", (req, res) => res.json(posts));
app.post("/api/posts", (req, res) => {
const post = { id: posts.length + 1, title: req.body.title };
posts.push(post);
res.status(201).json(post);
});
app.listen(3000, () => console.log("API on http://localhost:3000"));
Core Node.js concepts
| Concept | What it means |
|---|---|
| Event loop | Handles many connections without blocking, using asynchronous I/O |
| Modules | ES modules (import) and CommonJS (require) |
| Built-in modules | node:fs, node:path, node:http, node:crypto |
| Environment variables | process.env; load .env files with node --env-file=.env |
| Async/await | The standard way to handle promises |
Popular Node.js frameworks
- Express — minimal and widely used.
- Fastify — fast with built-in schema validation.
- NestJS — structured, TypeScript-first, Angular-style architecture.
- Hono — lightweight and runs on many runtimes.

Deploying Node.js apps
Common options include Render, Railway, Fly.io, cloud platforms (AWS, Google Cloud, Azure) and VPS hosting with a process manager such as PM2 behind Nginx. See VPS vs shared hosting.
Warning: Never commit secrets such as API keys to Git. Store them in environment variables and add .env to .gitignore.
A tidy project structure
| Folder or file | Purpose |
|---|---|
src/routes/ |
URL routes, grouped by feature |
src/controllers/ |
Logic for each route |
src/services/ |
Business logic and database access |
src/middleware/ |
Authentication, validation and error handling |
.env |
Secrets and configuration (never committed) |
tests/ |
Automated tests |
Next steps after your first API
- Add validationCheck incoming data before using it.
- Connect a databasePostgreSQL or MongoDB with a library or ORM.
- Add authenticationSessions or tokens for protected routes.
- Handle errors consistentlyOne error-handling middleware.
- Write testsFor routes and services.
- DeployTo a platform such as Render, Railway or a VPS.
Next: TypeScript tutorial, REST API vs GraphQL and frontend vs backend.
Frequently asked questions
What is Node.js used for?
Building web servers, REST and GraphQL APIs, real-time apps, command-line tools and front-end build tooling.
Is Node.js a programming language?
No. Node.js is a runtime that runs JavaScript outside the browser.
Should I learn Node.js or PHP?
Both are widely used. Node.js lets you use JavaScript on both front end and back end; PHP powers WordPress and Laravel.
Which Node.js version should I use?
Use the current LTS version for production because it receives long-term security updates.
Can Node.js work with WordPress?
Yes, for example by building a front end or tools that use the WordPress REST API, or for build tooling in theme and block development.
Is Express still worth learning?
Yes. Express is widely used and teaches core concepts that transfer to Fastify, NestJS and other frameworks.
How do I keep Node.js apps running in production?
Use a process manager such as PM2 or a platform that handles restarts, plus monitoring and logging.
Further reading: MDN’s web development learning area.







