Express Server Setup in Node.js

From the Express.js REST API cheat sheet ยท Express.js Basic Setup ยท verified Jul 2026

Express Server Setup

Create and configure a basic Express server with essential middleware

javascript
const express = require('express');
const app = express();

// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Basic route
app.get('/', (req, res) => {
  res.json({ message: 'Hello World!' });
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});
๐ŸŸข Essential - Every Express app starts with this setup
๐Ÿ’ก Use dotenv for environment variables in production
โšก Enable cors() for cross-origin requests from frontend
๐Ÿ“Œ Body parsers (json/urlencoded) required for POST requests
๐Ÿ”— Related: helmet for security headers, compression for gzip

Continue with Express.js REST API

Save the full cheat sheet or work through every related task.

More Node.js tasks

Back to the full Express.js REST API cheat sheet