Express middleware for people who are anal about trailing slashes.

npm install express-slash
2 downloads in the last day
101 downloads in the last week
378 downloads in the last month

Express Slash

Dependency Status npm Version

Express middleware for people who are anal about trailing slashes.

If you're a good person, then you enable Express' "strict routing" because you understand the difference between /about and /about/. You know that these URLs are not the same and they have different meanings. The trouble is, being a good person and caring about your trailing slashes is harder than not. Plus, you also care about other people, and it would be rude to 404 them when they forget the trailing slash. Luckily, there's this package to solve all your trailing slash problems :D

This Express middleware should come after your app's router middleware. It will handle [GET and HEAD] requests for URLs which did not have a matching route by either adding or removing a trailing slash to the URL's path, then checking the app's router for a matching route for the new URL, in which case it will redirect the client (301 by default) to that URL.


Install using npm:

$ npm install express-slash


Enable Express' "strict routing" setting, and add this middleware after your app's router middleware:

var express = require('express'),
    slash   = require('express-slash'),

    app = express();

// Because you're the type of developer who cares about this sort of thing!
app.enable('strict routing');

// Add the `slash()` middleware after your app's `router`, optionally specify
// an HTTP status code to use when redirecting (defaults to 301).

app.get('/', function (req, res) {

app.get('/about/', function (req, res) {

app.get('/about/people', function (req, res) {


Now when someone navigates to /about, they'll be redirected to /about/, and when someone navigates to /about/people/, they'll be redirected to /about/people.


This software is free to use under the MIT license. See the LICENSE file for license text and copyright information.

npm loves you