Express sits on top of Node.js HTTP handling and adds routing, middleware, and response helpers for web services. A minimal server is enough when you need a local endpoint to test route wiring before adding templates, databases, or deployment tooling.
A starter app can use a normal npm project, install Express as a local dependency, and keep the server in one CommonJS file. Binding to 127.0.0.1 keeps the development listener local to the machine while you prove the route with curl.
The server reads PORT from the environment and falls back to port 3000, which matches the conventional Express starter port. Keep this pattern for local development; production deployments usually add process management, logging, reverse proxy settings, and shutdown handling.
Related: How to create a Node.js project with npm
Related: How to install a Node.js dependency
Related: How to create an HTTP server in Node.js
Steps to create an Express server in Node.js:
- Create a project directory for the Express app.
$ mkdir express-demo
- Enter the project directory.
$ cd express-demo
- Initialize package metadata with npm.
$ npm init --yes
The command writes package.json with default metadata. Edit the name, license, or scripts later if the project needs specific values.
- Install Express as a local dependency.
$ npm install express added 67 packages, and audited 68 packages in 2s 25 packages are looking for funding run `npm fund` for details found 0 vulnerabilities
- Create the Express app file.
$ cat > app.js <<'EOF' const express = require('express'); const app = express(); const port = process.env.PORT || 3000; app.get('/', (req, res) => { res.type('text').send('Express server ready\n'); }); app.listen(port, '127.0.0.1', () => { console.log(`Express server listening at http://127.0.0.1:${port}`); }); EOFprocess.env.PORT lets a deployment or test runner choose another port while local runs fall back to 3000.
- Confirm Express is saved in the project dependency tree.
$ npm list express --depth=0 express-demo@1.0.0 /home/developer/express-demo `-- express@5.2.1
- Start the Express app.
$ node app.js Express server listening at http://127.0.0.1:3000
Keep this terminal open while testing the route.
- Request the root route from another terminal.
$ curl -sS http://127.0.0.1:3000/ Express server ready
- Return to the server terminal and press Ctrl-C.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.