node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Build Status Dependency Status

This module takes express routes and redirects them to external or internal URLs.

It is very similar to redirects on NPM. In fact, I based my tests on the tests in redirects. The difference between the two is my one doesn't rely on any other external libraries, so doesn't have as many features, hence the name 'simple'.

npm install express-simple-redirect --save

Basic usage

var redirect = require('express-simple-redirect');
// a bunch of express route definitions 
  '/my-url': '',  // Redirect to external URL 
  '/info': '/about'                 // Internal redirect to /about page 

Custom response code

You can also add a redirect HTTP status code. By default, this code is 307 (Temporary Redirect). You may wish to change it to 301 for a permanent redirection by doing:

  // urls 
}, 301));

Note: Response code 301 adds an entry to the client browser cache, meaning that the browser won't hit your server again. 301 is not recommended for routes that may change.

Loading from a file

You may want to separate your redirects even further by putting them in a different file. This library doesn't have any special way of parsing files, so you need to convert it into a JavaScript object first. The easiest way to do this is by writing your redirects as a JSON file, then you can load it by using require().


  "/url": "",
  "/info": "/about",