Page Contents

You can easily add versioning to your REST API routes, based on the application “major” version in package.json.

Add a file named config.local.js in the application’s /server directory with the following code:


var p = require('../package.json');
var version = p.version.split('.').shift();
module.exports = {
  restApiRoot: '/api' + (version > 0 ? '/v' + version : ''),
  host: process.env.HOST || 'localhost',
  port: process.env.PORT || 3000

This takes the major version number from the version property in package.json and appends it to the REST API root. If your app’s major version is 0, then the REST API root remains the default /api.

So, for example, if version in package.json is 2.0.1, then the built-in model route exposed by default at:

GET http://localhost:3000/api/Users

is now exposed at:

GET http://localhost:3000/api/v2/Users