1.3.1 • Published 11 months ago

mx-file-router v1.3.1

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
11 months ago

mx-file-router logo

Fast, light-weight file based routing solution for Node.js.

NPM Version NPM Install Size NPM Downloads


Version notices

v1.2.0beta + Added support for CJS files(lightly tested, might not work as expected)

v1.1.0beta

+ /routes subfolder support(not tested, might not work as expected)

Usage

const express = require('express')
const Router = require('mx-file-router')
const app = express()

Router.start(app, {
    port: 3000,                 // default: 3000
    controllers: 'controllers', // default: 'controllers'
    extraLogs: true             // default: false
})

Example methods

MethodFile
GEThome.get.js
HEADhome.head.js
POSThome.post.js
PUThome.put.js
DELETEhome.delete.js
CONNECThome.connect.js
OPTIONShome.options.js
TRACEhome.trace.js
PATCHhome.patch.js

To create a route, first create a folder in the project root named controllers. After that, you can create .js files like the examples above.

Write the following code inside the newly created route file:

// (REQUIRED) Point one or more endpoint(s) to the same location.
exports.endpoints = ['/']

// (OPTIONAL) Easily add middleware to your route.
exports.middleware = authMiddleware.isAdmin()

// (REQUIRED) The handler of this file.
exports.handler = async (req, res) => {
    res.status(200).send('<h1>Homepage</h1>')
}

Installation

Before installing, you will have to download and install Node.js. Node.js v10.0 or higher is required.

If this is a new project, you will have to create a package.json. This can easily be done with the npm init command.

Installing the package

$ npm install mx-file-router
$ npm update

Dependencies Express will be automatically installed as a dependency.

More information on installing npm packages can be found here.

Features

  • Low-code setup
  • Easy to use
  • Low file size

License

GPL 3.0

1.3.1

11 months ago

1.3.0

11 months ago

1.2.0

1 year ago

1.2.0-beta

1 year ago

1.1.0-beta

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago