Load ExpressJS routes dynamic at runtime by placing them into a specified folder.

Usage no npm install needed!

<script type="module">
  import expressPlugableRoutes from '';


Express Plugable Routes

Load ExpressJS routes dynamic at runtime by placing them into a specified folder.


npm install express-plugable-routes

yarn add express-plugable-routes

How to use

How to initialise the module

In your project, first declare the module

const express = require('express');
const ExpressPlugableRoutes = require('express-plugable-routes');

const app = express();

// add your regular ExpressJS middleware and other logic such as:

 * Add your 404 error logic here
function error404(req, res, next){

 * Add your other error logic here
function errorHandler(req, res, next){

Next, gather the required parameters and create a new instance

const addonFolder = `${__dirname}/addons`; // This is the folder where you drop your runtime plugable routes in
const watchFor = `${addonFolder}/**/config.json`; // The file to watch which contains all the required information about the new route. See Chokidar for more info on this
const chokidarOpts = {ignored: /^\./, persistent: true}; // The options for Chokidar

new ExpressPlugableRoutes(app, addonFolder, watchFor, chokidarOpts, error404, errorHandler);

// That's it!

module.exports = app;

How to list the added routes

To prevent running and requiring an external database, an 'in-memory' database (LokiJS) is used.

So getting a list of installed routes is easily achieved:

const Loki = require('lokijs');

const db = new Loki('ExpressPlugableRoutes');
db.loadDatabase({}, function() {

Required in the 'config.json'

The bare minimum should contain:

    "expressPlugableRoutes": {
        "name": "myCustomRoutes",               // name of the module
        "main": "index.js",                     // incoming js file to use 
        "path": "/base-url-of-the-routes",      // base url the module is mounted on
        "rootFolder": "myCustomRoutesFolder"    // folder path relative to the addon folder up to the main file




Copyright (©) 2018 Max van de Laar