Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gulp task to show the routes in an express app (similar to rails rake routes).
var app = require('../server/app.js').create()
var gulp = require('gulp');
var task = require('./index');
Output all the routes that the app supports
gulp.task('routes', function() {
var paths = {};
for (method in app.routes) {
// there's a slew of methods we don't care about
if (-1 == ['get', 'post', 'put', 'delete', 'options'].indexOf(method)) break;
var routes = app.routes[method];
for (i in routes) {
path = routes[i].path;
paths[path] = paths[path] || {};
paths[path].methods = paths[path].methods || [];
if (-1 == paths[path].methods.indexOf(method))
console.log('Here are the routes the app supports:');
for (path in paths) {
console.log(path, paths[path].methods);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment