https://github.com/evheniy/yeps
Yet Another Event Promised Server
https://github.com/evheniy/yeps
async await http http-server nodejs promise
Last synced: 6 months ago
JSON representation
Yet Another Event Promised Server
- Host: GitHub
- URL: https://github.com/evheniy/yeps
- Owner: evheniy
- License: mit
- Created: 2017-02-11T10:49:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-15T15:28:16.000Z (about 8 years ago)
- Last Synced: 2025-08-07T05:20:09.565Z (6 months ago)
- Topics: async, await, http, http-server, nodejs, promise
- Language: JavaScript
- Homepage:
- Size: 36.1 KB
- Stars: 16
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yet Another Event Promised Server
Simple promised node http request-response handler
[](https://npmjs.org/package/yeps)
[](https://badge.fury.io/js/yeps)
[](https://travis-ci.org/evheniy/yeps)
[](https://coveralls.io/github/evheniy/yeps?branch=master)
[](https://travis-ci.org/evheniy/)
[](https://ci.appveyor.com/project/evheniy/yeps)
[](https://david-dm.org/evheniy/yeps)
[](https://david-dm.org/evheniy/yeps#info=devDependencies)
[](https://travis-ci.org/evheniy/yeps)
[](https://snyk.io/test/github/evheniy/yeps)
[](https://raw.githubusercontent.com/evheniy/yeps/master/LICENSE)
[](https://github.com/evheniy/yeps/stargazers)
[](https://github.com/evheniy/yeps/network)
[](https://github.com/evheniy/yeps/issues)
[](https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D)
## 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](http://yeps.info/)