Skip to content

Instantly share code, notes, and snippets.

View PierrePDP's full-sized avatar

Pierre Philip du Preez PierrePDP

  • Cape Town, South Africa
View GitHub Profile
@PierrePDP
PierrePDP / register.js
Created October 9, 2020 15:22
Dynamic route generation Express.js
registerRoutes(dir) {
//Check if recursive directory has been provided
if (!dir)
dir = '';
//Set the base directory
let baseDirectory = process.cwd() + '/routes';
//Set current directory
let currentDirectory = baseDirectory + dir;
//Get all items from directory passed with or base