1.1.0 • Published 2 years ago

@adahox/lightrouter v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

lightrouter

A faster way to build apis using nodejs.

Dependencies

Packageversion
Express^4.17.2

Installation

Install lightrouter package

  npm install --save ligthrouter

Add lightrouter package in your project

const lightrouter = require('lightrouter');

At root project folder create route.js file and paste the code bellow

module.exports = [
    {
        "/": [
            {
                "type":"post",
                "response": "{\"test\": \"working\"}"
            },
        ]
    },
];

You can also pass the path of a file as a value in the response attribute instead of a json object.

module.exports = [
    {
        "/": [
            {
                "type":"post",
                "response": "path/to/file/js/without/extension"
            },
        ]
    },
];

So, let lightrouter build your route.js file and see the magic.

...
const { lightRoute } = require('../index');
const route = new lightRoute;

app.use('/', (req, res, next) => { next() }, route.build(path.join(__dirname, '..', 'routes.js')));
...

here is all the code

const path = require('path');
const express = require('express');
const { lightRoute } = require('../index');
const app = express();
const lightrouter = new lightRoute;

const routerFile = path.join(__dirname, '..', 'routes.js');

app.use('/', (req, res, next) => { next() }, lightrouter.build(routerFile) );

app.listen(3000, () => console.log('listening at port 3000'));