From `npm init` to a Running Server in 60 Seconds
Installing Express
Spin up a fresh Express app from scratch. No generator, no boilerplate — just npm install and 6 lines of code.
What you'll learn
- Initialize a new project
- Install Express 5
- Run your first server
You don’t need a generator for Express. The minimum-viable setup is three commands.
Step 1 — Create the Project
mkdir my-api
cd my-api
npm init -y npm init -y creates package.json with sensible defaults.
Step 2 — Set Module Type
Open package.json and add "type": "module":
{
"name": "my-api",
"version": "1.0.0",
"type": "module",
"main": "src/index.js",
"scripts": {
"dev": "node --watch src/index.js"
}
} "type": "module" lets you use import instead of require.
Step 3 — Install Express
npm install express For Express 5 specifically:
npm install express@5 (At time of writing, express@latest is Express 5 — but pinning is
safer.)
Step 4 — Write the Server
// src/index.js
import express from "express";
const app = express();
app.get("/", (req, res) => {
res.send("Hello, Express!");
});
const port = 3000;
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
}); Step 5 — Run
npm run dev Visit http://localhost:3000 — you should see “Hello, Express!”.
With --watch, the server auto-restarts on file changes.
The Express Generator
For larger scaffolds, there’s npx express-generator — it spits out
a Pug-templated project with the older Express 4 conventions. We
skip it; the hand-rolled setup above is cleaner for modern apps.
TypeScript Setup
Adding TypeScript? Install:
npm install --save-dev typescript @types/node @types/express tsx Then run with npx tsx src/index.ts. We cover this more deeply in
the TypeScript track.