
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
express-promise-middleware
Advanced tools
Write express middleware that wait on Promises before they respond or call next
This module exports two handy functions that let you write express middleware that wait on Promises
before they respond or call next
. Nothing fancy really. Comes with flowtypes if you use those.
promiseMiddleware
Returns express middleware that runs provided function, and when complete, calls next()
for you.
If there is an error, it catches the error and passes it along to next()
like a good express citizen.
Also, the provided middleware returns a promise that is resolved whenever the middleware is done. Why not? It's helpful for tests. Even if the handler throws, though, the promise will resolve without an error so you don't have to deal with uncaught exceptions.
import {promiseMiddleware} from 'express-promise-middleware';
router.use(promiseMiddleware(function (req, res) {
return Promise.resolve()
.then(function () {
/*
* do something async, the next middleware will wait
* 'till this one is done
*/
});
}));
respondJSON
Returns express middleware that runs provided function, expects a promise back, and uses the express res.json() function to send along the response.
If there is an error, it catches the error and passes it along to next()
like a good express citizen.
Also, the provided middleware returns a promise that is resolved whenever the middleware is done. Why not? It's helpful for tests. Even if the handler throws, though, the promise will resolve without an error so you don't have to deal with uncaught exceptions.
import {respondJson} from 'express-promise-middleware';
router.get('/my-endpoint', respondJson(function (req, res) {
res.setStatus(201);
return Promise.resolve(
'This is a string response object! It can be ' +
'whatever you want, so long as it\'s valid JSON!' +
'When this promise resolves, express will respond ' +
'to the request.';
);
});
FAQs
Write express middleware that wait on Promises before they respond or call next
We found that express-promise-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.