express-swift-router

1.0.1 • Public • Published

Express Swift Router

A unique package created by programmers city developer to help improve routing system on node.js and express.

This package is designed to assist web developers to easily and swiftly create route files and make use of an internally built Express.js App to registers the routes and making them available.

INSTALLATION

To install the package, simply run npm i express-swift-router and the package as well as all its dependencies will be installed.

Usage

The router can be used to organize all the routes on your application and registering them on an Express.js App router implicitly. To do this, you need to create a route file, eg. routes.js in which all the routes will be defined like the example shown below;

const ApiRoute = require('express-swift-router');
const apiRoute = new ApiRoute();

apiRoute.get('/', (req, res) => {
    res.send('Hello World');
});

apiRoute.get('/test', (req, res) => {
    res.send('Hello World Test Page');
});


apiRoute.registerRoutes();

The above example will imports/uses the ApiRoute class to organize all the routes as well as prepend /api/ to all the routes defined in the route.js file. Alternatively, you can use the WebRoute class if you do not want the prefix api on the routes. Example is shown below;

const WebRoute = require('express-swift-router');
const webRoute = new WebRoute();

webRoute.get('/', (req, res) => {
    res.send('Hello World');
});

webRoute.get('/test', (req, res) => {
    res.send('Hello World Test Page');
});


webRoute.registerRoutes();

Starting the Server

While registering the routes with the registerRoutes() method, a global variable named activeServer will be created which is an instance of Express.js App in which all the routes have been registered. Therefore, running the command activeServer.start() will fireup the express and make all routes accessible and functional.

Package Sidebar

Install

npm i express-swift-router

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

10.8 kB

Total Files

7

Last publish

Collaborators

  • destinyb