tezvyn:

Minimal Express Hello World server

AI-drafted, machine-checkedSource: interviewbeginner
WHAT IT TESTS

basic Express setup fluency.

OUTLINE

import express, create an app, define app.get on the root sending a response, call app.listen on a port.

RED FLAG

forgetting app.listen or confusing the require with the app instance.

WHAT THIS TESTS This verifies baseline Express familiarity, the starting point for every Express discussion. It quickly reveals whether someone has actually built with the framework.

A GOOD ANSWER COVERS You require the express module, which exports a factory function, and call it to create an application instance, conventionally named app. You define a route by calling app.get with the path '/' and a handler function receiving the request and response objects, where you call res.send('Hello, World!') to send the body; Express automatically sets a 200 status and an appropriate Content-Type. Finally you call app.listen with the port number and usually a callback that logs that the server is running. That is the entire minimal program. Express handles the underlying http server creation, the response finalization, and content-type detection for you, which is why this is shorter than the equivalent raw http module code.

COMMON WRONG ANSWERS Forgetting to invoke express() and trying to call get on the module itself. Omitting app.listen, so the routes exist but nothing binds a port. Using the raw http module patterns like manually calling res.end with headers when Express provides res.send.

LIKELY FOLLOW-UPS How does res.send differ from res.json and res.end. How would you add middleware. How do you read query and route parameters in the handler.

ONE CONCRETE EXAMPLE The full program: const express = require('express'); const app = express(); app.get('/', (req, res) => res.send('Hello, World!')); app.listen(3000, () => console.log('Server on 3000'));. A GET to http://localhost:3000/ returns Hello, World! with a 200 status, and the listen callback confirms the server bound to the port.

Read the original → expressjs.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.