Create an application by calling express(), register a route on it, and start the server with app.listen(). Install the package first with npm install express.
const express = require('express');
const app = express();
const PORT = 3000;
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
app.get('/', ...) registers a route handler that runs for GET requests to the root path, and res.send() writes the response. The server listens on port 3000 and answers the root route with Hello World!. Express answers every other path with 404 Not Found. app.listen() returns the Node.js http.Server it creates, which you keep when you need to close the server later.
Rewriting in plainer words…
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.