Skip to content

Instantly share code, notes, and snippets.

@xjamundx
Last active December 11, 2015 08:48
Show Gist options
  • Select an option

  • Save xjamundx/4575166 to your computer and use it in GitHub Desktop.

Select an option

Save xjamundx/4575166 to your computer and use it in GitHub Desktop.
Versioned APIs with Express
// define the versions
var VERSIONS = {'Pre-Production': '/v0', 'Version 1': '/v1'};
// route to display versions
app.get('/', function(req, res) {
res.json(VERSIONS);
})
// versioned routes go in the routes/ directory
// import the routes
for (var k in VERSIONS) {
app.use(VERSIONS[k], require('./routes' + VERSIONS[k]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment