Guide · Open source
How to use Express: install, routes and responses
Updated · written with AI from the project's own documentation and checked against our catalogue data
Express is a small web framework for Node.js, the JavaScript runtime that runs outside the browser. It helps you handle incoming web requests, define routes and send responses without writing all the low-level server code yourself. This guide is for developers and learners who want to set up Express in a project and understand the basic pattern it uses.
Quick start
- 1Install Node.js. Make sure Node.js is installed, since Express runs on it.
- 2Set up a project folder. Open a terminal in the folder where your project will live.
- 3Install Express. Run npm install express inside the project folder.
- 4Write your first script. Create a JavaScript file that loads Express, creates an app and defines a route.
- 5Start the server. Run your script with Node.js and listen on a port.
- 6Test a route. Open the route address in a browser or with a tool and check the response.
- 7Read the docs. Use the official documentation at expressjs.com for examples and API details.
What Express does and who it is for
Express is described as fast, unopinionated and minimalist. In practice that means it gives you a thin layer over Node.js for handling requests and responses, and it leaves most structural decisions, such as folder layout and which libraries to use, to you.
It suits developers building JavaScript or Node.js back-end servers, teams building REST-style APIs in Node.js, and learners who want to see how a web server handles requests. It is a poor fit if you want a batteries-included framework with conventions decided for you, or if you do not write JavaScript.
- Good fit: Node.js back ends, REST-style APIs, small framework with your own library choices
- Poor fit: full framework with fixed conventions, non-programmers, projects not using Node.js
Install Express with npm
Express is installed with a package manager and requires Node.js. Open a terminal in your project folder and run the install command from the project's README to add Express to that project.
- Prerequisite: Node.js installed on your machine
npm install expressCreate a basic server and route
Once Express is installed, you load it in a JavaScript file, create an app, and define routes. A route tells the server what to send back when a request arrives for a given path. The examples in the official documentation at expressjs.com show the full setup, including how to start the server and listen on a port.
- Require or import express in your script
- Create an app instance
- Define a route for a path and send a response
- Start the server so it listens for requests
Handle requests and send responses
Each route handler receives the incoming request and a response object. You read data from the request, such as URL details or body content, and use the response to send text, JSON or other output back to the client. This request-in, response-out model is the core of how Express is used.
Because Express is minimal, features such as parsing or validation are typically added through other libraries you choose. Check the documentation at expressjs.com for the current list of built-in helpers.
Build a REST-style API with Express
For REST-style APIs, you typically define one route per resource and action, for example a path for listing items and another for creating one. Express gives you the routing layer; you decide the URL design, data storage and response format.
- Pick resource paths and HTTP methods for each action
- Return JSON or other responses from each handler
- Add your own libraries for database access and validation
Compare Express with other Node.js frameworks
Comparable projects include Fastify, Koa, Hapi and NestJS. Express is the smallest-footprint choice of the group in its own description, while NestJS offers more structure out of the box. Compare them on how much structure you want to write yourself before choosing.
- Choose Express for a minimal core and your own library choices
- Consider NestJS if you want more conventions decided for you
What people use it for
- Back-end server for a JavaScript web app
- REST-style API for a mobile or web client
- Small internal tool that serves data over HTTP
- Learning project to understand how web requests are handled
Frequently asked questions
How do I install Express?
Express is installed with npm, the package manager that comes with Node.js. Run npm install express inside your project folder to add it to that project.
Do I need Node.js to use Express?
Yes. The source lists Node.js as the prerequisite, because Express is a framework for Node.js and does not run in the browser or on projects that do not use Node.js.
Is Express free and open source?
Express is released under the MIT licence, which is an open-source licence. The source does not list pricing, so the code is the basis for what it costs to use.
What is Express used for?
Express is used to handle web requests, define routes and send responses in Node.js. It is commonly used for back-end servers and REST-style APIs.
What are alternatives to Express?
Comparable projects named in the source include Fastify, Koa, Hapi and NestJS. Pick based on how much structure you want the framework to provide.
Is Express good for beginners?
It is a reasonable choice for learners who want to understand how web servers handle requests, because it is small. Beginners who want a full framework with fixed conventions may find it leaves too many decisions to them.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Express suits developers who want a small Node.js framework and prefer choosing their own libraries and structure. If you want conventions decided for you, or you do not write JavaScript, pick a fuller framework or a different tool.
Install options & downloads