
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
middleware-async
Advanced tools
A handy tool to write async/promise style middleware for express, connect-like.
Lets check at this code
app.use(async (req, res, next) => {
req.user = await User.findById(req.params.id).exec()
next()
})
The next()
will be executed after User.findById(...).exec()
is fulfilled because express allow middleware returning Promise.
However, express does not support if promise returned by the middleware is rejected. The followings middlewares will never be called.
Solution is simple by wrapping the middleware with
import middlewaareAsync from 'middleware-async'
app.use(middlewaareAsync(async (req, res, next) => {
req.user = await User.findById(req.params.id).exec()
next()
}))
Install it via npm or yarn
npm install --save middleware-async
#or
yarn add middleware-async
middlewaareAsync(middlware)
: return a middleware that covers error thrown or error that is rejected by middleware
combineMiddlewares(list of middlewares or list of list of middlewares)
: combine many middlewares into one middleware. Very useful for testingmiddlewareToPromise
: convert express-style middleware into PromisecombineToAsync
: combination of middleewareToPromise
and combineMiddlewares
import middlewareAsync, {combineMiddlewares, combineToAsync, middlewareToPromise} from 'middleeware-async'
describe('combineMiddlwares', () => {
it('should go through all middlewares', async () => {
const req = {val: 0}
await combineToAsync([
async (req, res, next) => {
await Promise.resolve()
req.val += 1
next()
},
(req, res, next) => {
req.val++
next()
},
])(req)
expect(req.val).to.equal(2)
})
})
FAQs
A handy tool to work with async/promise express middleware
The npm package middleware-async receives a total of 1,225 weekly downloads. As such, middleware-async popularity was classified as popular.
We found that middleware-async 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.