oo-server
v0.1.1
Published
An object-oriented Express server.
Downloads
1
Readme
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