How do you create a basic Express.js server?

Why Interviewers Ask This

This is a classic screening question for Express.js roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

Install Express with npm install express, then create a server in a few lines: const express = require('express'); const app = express(); app.get('/', (req, res) => res.send('Hello World')); app.listen(3000);. express() creates an application instance. app.get() registers a route handler for HTTP GET requests. The handler receives a req (request) and res (response) object. res.send() sends a response. app.listen(port) starts the HTTP server. This is all you need for a minimal web server. In modern Node.js projects you can also use ES modules with import express from 'express' if your package.json has "type": "module".

Pro Tip

This topic has Express.js-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.