express-log-routes

console.log available Express routes

Usage no npm install needed!

<script type="module">
  import expressLogRoutes from 'https://cdn.skypack.dev/express-log-routes';
</script>

README

express-log-routes NPM version Build Status Dependency Status

console.log available Express routes

Installation

$ npm install --save express-log-routes

Usage

var router = require('express').Router();
var LogRoutes = require('express-log-routes');

// Initialize with the default configuration:
/*
{
  baseUri: '/',
  router: undefined,
  headerTemplate: function () {
    return `---------------------\nROUTES AVAILABLE FOR: ${this.baseUri}\n---------------------`;
  },
  uriTemplate: function (method, uri, endpoint) {
    return `==> ${method.toUpperCase()} ${endpoint}`;
  },
  footerTemplate: function () {
    return '';
  },
  whilst: function () {
    return true;
  }
}
*/
var logRoutes = LogRoutes();

// or, customize the initial configuration
var options = {
  whilst: function() {
    // only during dev
    if (process.env.ENV === 'dev') {
      return true;
    }
    return false;
  }
};
logRoutes = LogRoutes(options);

// ...

// Note: if you pass a router into the initial configuration,
//       you can then simply activate the logging with:
//
//         logRoutes();
//
// Otherwise: activate logging for a specific router:
logRoutes({
  router: router,
  baseUri: '/api/user' // <-- you can also override initial configurations
});

License

ISC © Buster Collings