1.1.1 • Published 6 years ago
yeps v1.1.1
Yet Another Event Promised Server
Simple promised node http request-response handler
How to install
npm i -S yeps
How to use
app.js
const App = require('yeps');
const app = module.exports = new App();
app.then(async (ctx) => {
ctx.res.statusCode = 200;
ctx.res.setHeader('Content-Type', 'application/json');
ctx.res.end('{"status":"OK"}');
});
app.catch(async (error, ctx) => {
ctx.res.statusCode = 500;
ctx.res.setHeader('Content-Type', 'application/json');
ctx.res.end(JSON.stringify({ error }));
});
bin/www
#!/usr/bin/env node
const http = require('http');
const app = require('../app');
http
.createServer(app.resolve())
.listen(parseInt(process.env.PORT || '3000', 10));
package.json
"scripts": {
"start": "node bin/www"
}
Breaking chain
app.then(async (ctx) => {
ctx.res.statusCode = 200;
ctx.res.setHeader('Content-Type', 'application/json');
ctx.res.end('{"status":"OK"}');
return Promise.reject();
}).then(async () => {
// it won't work
}).catch(async () => {
// it won't work
});
Using router
npm i -S yeps-router
app.js
const App = require('yeps');
const Router = require('yeps-router');
const app = module.exports = new App();
const router = new Router();
router.get('/').then(async (ctx) => {
ctx.res.statusCode = 200;
ctx.res.setHeader('Content-Type', 'application/json');
ctx.res.end('{"status":"OK"}');
});
app.then(router.resolve());
Using server
npm i -S yeps-server
bin/www
#!/usr/bin/env node
const server = require('yeps-server');
const app = require('../app');
server.createHttpServer(app);
Error handler
npm i -S yeps-error yeps-logger
app.js
const App = require('yeps');
const error = require('yeps-error');
const logger = require('yeps-logger');
const app = module.exports = new App();
app.all([
error(),
logger(),
]);
YEPS documentation
1.1.1
6 years ago
1.1.0
6 years ago
1.0.1
7 years ago
1.0.0
7 years ago
0.0.17
7 years ago
0.0.16
7 years ago
0.0.15
7 years ago
0.0.14
7 years ago
0.0.13
7 years ago
0.0.12
7 years ago
0.0.11
7 years ago
0.0.10
7 years ago
0.0.9
7 years ago
0.0.8
7 years ago
0.0.7
7 years ago
0.0.6
7 years ago
0.0.5
7 years ago
0.0.4
7 years ago
0.0.3
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago