Is it possible to make async.waterfall method work in a Next JS endpoint?
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
I use waterfall, parallel and series from the async package a lot in Node JS applications, but when I tried async.waterfall it would always give me the following error:
- error TypeError: Cannot read properties of undefined (reading 'headers')
Please, note that I'm using App router.
The error is the result from executing the following function:
- error TypeError: Cannot read properties of undefined (reading 'headers')
Please, note that I'm using App router.
The error is the result from executing the following function:
export async function PUT(req: NextApiRequest, { params }: paramsType) {
try {
waterfall([
function (callback) {
console.log("fired 1")
const message = "fired 2"
callback(null, message)
},
function (message, callback) {
console.log('message: ', message)
const message2 = "fired 3"
callback(null, message, message2)
}
], (err, message2) => {
if (err) {
console.log(err)
return new NextResponse(JSON.stringify(err), { status: 500 })
}
console.log(message2)
return new NextResponse(JSON.stringify(null), { status: 200 })
})
} catch (error) {
return new NextResponse(JSON.stringify(error), { status: 500 })
}
}