0.1.1 • Published 7 years ago

oo-server v0.1.1

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

js-oo-server

An object-oriented Express server.

Usage

npm install oo-server

In index.js:

const Server = require('oo-server');
const homeRouter = require('./home.router.js');
const blogRouter = require('./blog.router.js');

const server = new Server('My Server', 8080) // PORT is required
    .use(homeRouter)
    .use(blogRouter)
    .start()
    .catch(onServerStartError); // implement an error handler

...

server.stop()
    .catch(onServerStopError); // implement an error handler

In home.router.js:

const { Router } = require('oo-server');

module.exports = new class HomeRouter extends Router {

    constructor () {
        super();

        // Implement endpoints as you usually would in Express
        this.use('/', (req, res, next) => {
            res.json({ results: [] });
        });
    }

}

Testing

npm test