x-route-builder
TypeScript icon, indicating that this package has built-in type declarations

1.3.4 • Public • Published

x-route-builder

A light-weight utility for creating file based routing in frameworks like express.

Features:

  • File-based routing.
  • Can ignore files.
  • Can alter the file's route that is created.
  • Dynamic routes (req.params) - File:[id].js - Will be altered to /:id.
  • Dynamic middleware - Place _middleware.js file in routes directory. The middleware will be applied to all routes inside the directory but will not be applied to routes above the directory.
  • Fully customizable.
  • Will log the output if in development env.

Table of Contents

  1. Install
  2. Usage

Install

npm i x-route-builder 

Usage

Standard:

const Xrouter = require('x-route-builder')

// create the route builder passing in (app)
const xRouter = new XrouteBuilder({
  app: app,
})

// build the routes
xRouter.build()

Options:

const Xrouter = require('x-route-builder')

// create the route builder passing in (app & options)
const xRouter = new XrouteBuilder({
  // app
  app: app,
  // directory path to start reading and building routes in
  dirpath: path.join(__dirname, 'routes'),
  // base path to start routes from
  basepath: '/basepath',
  // files to ignore
  ignore: [
    'ignoreFile1.js', 'ignoreFile2.js'
    ],
  // files to change / keep index of new route names the same as files
  change: {
    file: [
      'file1.js', 'file2.js'
    ],
    new: [
      'newFile1Path', 'newFile2Path'
    ],
  }
})

// build the routes
xRouter.build()

Package Sidebar

Install

npm i x-route-builder

Weekly Downloads

3

Version

1.3.4

License

MIT

Unpacked Size

14 kB

Total Files

5

Last publish

Collaborators

  • clyng57