Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including yeps with all npm packages installed. Try it out:

var yeps = require("yeps")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

yeps v1.1.1

Yet Another Event Promised Server

Yet Another Event Promised Server

Simple promised node http request-response handler

NPM

npm version Build Status Coverage Status Linux Build Windows Build

Dependency Status devDependency Status NSP Status

Known Vulnerabilities License GitHub stars GitHub forks GitHub issues Twitter

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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free