Express Setup

Create a project, install Express, and write a first server. It takes only a few lines to get a working web server.

Install

bash
npm init -y
npm install express

Set "type": "module" in package.json to use import syntax (as this course does).

A first server

server.js
import express from "express";
const app = express();

app.get("/", (req, res) => {
  res.send("Hello, Express!");
});

app.listen(3000, () => console.log("http://localhost:3000"));

The app object

express() creates your application. You register routes (app.get, app.post, ...) and middleware (app.use) on it, then app.listen(port) starts the HTTP server.

Running & auto-reload

bash
node server.js          # run once
node --watch server.js  # restart automatically on file changes

--watch (built into modern Node) restarts on save. Older projects use nodemon for the same thing.

Tip: Add a script to package.json ("dev": "node --watch server.js") so you can just run npm run dev.
Free preview. Sign in and subscribe to unlock all 809 lessons across 25 courses.
Express Setup β€” Express.js | Full Stack Learning Simplified