Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
express-yields
Advanced tools
Readme
A dead simple ES6 generators and ES7 async/await support hack for ExpressJS
npm install express-yields --save
Then require this script somewhere before you start using it:
const express = require('express');
const yields = require('express-yields');
const User = require('./models/user');
const app = express();
app.get('/users', function* (req, res) {
const users = yield User.findAll(); // <- some Promise
res.send(users);
});
// or with node 7 async/await
app.get('/users', async (req, res) => {
const users = await User.findAll(); // <- some Promise
res.send(users);
});
next
As we all know express sends a function called next
into the middleware, which
then needs to be called with or without error to make it move the request handling
to the next middleware. It still works, but in case of a generator function, you
don't need to do that. If you want to pass an error, just throw a normal exception:
app.use(function * (req, res) {
const user = yield User.findByToken(req.get('authorization'));
if (!user) throw Error("access denied");
});
// the same with Node 7 async/await
app.use(async (req, res) => {
const user = await User.findByToken(req.get('authorization'));
if (!user) throw Error("access denied");
});
This is a minimalistic and unintrusive hack. Instead of patching all methods
on an express Router
, it wraps the Layer#handle
property in one place, leaving
all the rest of the express guts intact.
The idea is that you require the patch once and then use the 'express'
lib the
usual way in the rest of your application.
All code in this repository released under the terms of the ISC license.
Copyright (C) 2016 Nikolay Nemshilov
FAQs
ES6 Generators support for expressjs
The npm package express-yields receives a total of 116 weekly downloads. As such, express-yields popularity was classified as not popular.
We found that express-yields demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.