CodeBlanks Logo Icon CodeBlanks

What is Express?

Learn what the Express framework is and how to install it.

What is Express?

Express is the most popular web framework for Node.js. It wraps the built-in http module and makes routing, request handling and sending responses easier. With Express you can set up a web server in a few lines.

Express is not built in; you install it with npm install express. Then you import it with const express = require("express");. Express is built on top of http.createServer, but it lets you write far less code. For example, defining a route is one line in Express, but an if-else chain in the raw http module. That is why most Node.js web projects start with Express.

Why Express?

Express simplifies many things compared to the http module. For routing you just write app.get("/path", handler); no if-else chain. For a JSON response res.json(data) is one line.

Express also gives middleware support: app.use(express.json()) automatically parses incoming JSON bodies. This is a task you do by hand in the http module. Express's simplicity makes it usable in projects of any size, from a small API to a large web app. In this group you will learn the core tools of Express: express(), app.get, app.post and app.listen.

Practice Import Express

Import the express module with require. Print "Express ready" with console.log.

Starter code

index.js
// Import the express module
// write here

// Print "Express ready"
// write here

Sample solution

index.js
const express = require("express");
console.log("Express ready");

Expected output

Express hazır

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 How is Express imported?

index.js
const express = require("express")
  • const express = require("http")
  • import express from "node"
  • const express = new Express()
  • const express = require("express") Correct answer

Explanation: Express is imported with require('express').

2 Complete the module name

Question
const express = require("____");
Answer
const express = require("express");

Explanation: The Express module is loaded as 'express'.

3 Match each piece to its role

Term Meaning
express Web framework
npm install Installs the module
require Imports the module
app Express application

All lessons in Intermediate