Creating Your First Express Server

Think of an Express app as three steps: require the library, create an instance, and listen on a port. This is the foundation for any Express-based API or web server.
Why it exists
Node.js provides low-level HTTP modules to build web servers, but they are verbose and require manually parsing URLs, headers, and request bodies. Express was created to provide a minimal, unopinionated layer on top of Node's native HTTP server to simplify routing, middleware, and response handling.
The mental model
Think of express() as a factory that creates a request-handling machine. You give this machine instructions (routes like app.get()) for what to do when a request arrives. Finally, you turn the machine on and connect it to a network port using app.listen(), so it can start receiving those requests.
How it works
The process involves three main steps. First, you import the Express library using const express = require('express'). Second, you create an application instance by calling the top-level express() function: const app = express(). This app object has methods for routing HTTP requests. Third, you define at least one route, like app.get('/', (req, res) => { ... }), which tells the app how to respond to a GET request at the root URL. The req and res objects are the same ones provided by Node.js, just enhanced by Express. Finally, you bind the application to a port and start the server with app.listen(port, callback), which makes it run continuously, waiting for connections.
When to use it
This is the fundamental starting point for any project using the Express framework. You will use this pattern to create REST APIs, traditional web applications with server-side rendering, or simple microservices that need to communicate over HTTP. It is the "File > New Project" for backend JavaScript development.
When not to use it
You might not use this basic setup directly if you're using a higher-level framework built on top of Express, like NestJS, which handles this boilerplate for you. For a full application, you would also typically use the Express generator to create a more structured project with separate files for routes and views, rather than putting everything in one file.
One canonical example
const express = require('express');
const app = express();
const port = 3000;app.get('/', (req, res) => {
res.send('Hello World!');
});app.listen(port, () => {
console.log(Example app listening on port ${port});
});This code creates a server that listens on port 3000. When you visit http://localhost:3000/ in a browser, it responds with "Hello World!". For any other path, it returns a 404 Not Found.
Interview question
What is the main advantage of using Express.js compared to Node.js's native HTTP module for building web servers?
- a.It provides a complete solution for database integration and ORM.
- b.It offers built-in support for real-time communication using WebSockets.
- c.It automatically generates a structured project directory with separate files.
- d.It simplifies the process of defining routes, applying middleware, and handling responses.Correct
Why? this is the answer
The card states Express was created to simplify routing, middleware, and response handling, which are verbose with Node's native HTTP modules. Express itself is unopinionated about databases or project structure, and WebSocket support is not its primary advantage over native HTTP.
Just read this? Test yourself on what you have been reading.
Read the original → expressjs.com
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on express — each one lists the topics its interview covers.
See open roles