herver
is a modern server lib which aims at being versatile but lightweight.
- 💡
Promise
-based APIs - 📦 Built-in router support
- 🚀 High extensibility
- 🔧 Useful utilities
- 📚 TypeScript support
// import APIs
const { App, Router, createStaticHandler } = require('herver');
// create an app and a router
const app = new App(),
router = new Router();
// handle POST requests to `/echo` (e.g.: `POST /echo?msg=test`)
router.post('/echo', async (context, next) => {
// end the response with the query parameter `msg`
context.endWithContent('' + context.queries.get('msg'));
});
// serve all GET requests with corresponding static files in the public folder
router.get(/^\//, createStaticHandler('/path/to/public'));
// apply the router to the app and starts the app at port 8080
app.use(router.handler)
.listen(8080);