What does Express.js do in the MEAN stack? What does Express.js do in the MEAN stack? express express

What does Express.js do in the MEAN stack?


  • MongoDB = database
  • Express.js = back-end web framework
  • Angular = front-end framework
  • Node = back-end platform / web framework

Basically, what Express does is that it enables you to easily create web applications by providing a slightly simpler interface for creating your request endpoints, handling cookies, etc. than vanilla Node. You could drop it out of the equation, but then you'd have to do a lot more work in whipping up your web-application. Node itself could do everything express is doing (express is implemented with node), but express just wraps it up in a nicer package.

I would compare Express to some PHP web framework in the stack you describe, something like slim.


You can think of Express as a utility belt for creating web applications with Node.js. It provides functions for pretty much everything you need to do to build a web server. If you were to write the same functionality with vanilla Node.js, you would have to write significantly more code. Here are a couple examples of what Express does:

  • REST routes are made simple with things like
    • app.get('/user/:id', function(req, res){ /* req.params('id') is avail */ });
  • A middleware system that allows you plug in different synchronous functions that do different things with a request or response, ie. authentication or adding properties
    • app.use(function(req,res,next){ req.timestamp = new Date(); next(); });
  • Functions for parsing the body of POST requests
  • Cross site scripting prevention tools
  • Automatic HTTP header handling
    • app.get('/', function(req,res){ res.json({object: 'something'}); });

Generally speaking, Sinatra is to Ruby as Express is to Node.js. I know it's not a PHP example, but I don't know much about PHP frameworks.


Express handles things like cookies, parsing the request body, forming the response and handling routes.

It also is the part of the application that listens to a socket to handle incoming requests.

A simple example from express github

var express = require('express');var app = express();app.get('/', function(req, res){  res.send('Hello World');});app.listen(3000);

Shows the creation of the express server, creating a route app.get('/'... and opening the port to listen for incoming http requests on.