Skip to main content
deleted 27 characters in body
Source Link

S.Nakib has a great answer. I combined it with a more simple version of jfriend00's answer: I included the asyncHandler in the utils folder of my project which I use across all files and use it in the async middlewares

utils.js contains

const asyncHandler = fn => (req, res, next) => { fn(req, res, next).catch(next) } 

other.js contains

async function someAuthAsyncFunction(req, res, next) { await callToOtherService() next() } 

app.js contains

app.use(utils.asyncHandler(other.someAuthAsyncFunction)) 

This is worked for me as I'm working with routes and just a few middlewares are async

S.Nakib has a great answer. I combined it with a more simple version of jfriend00's answer: I included the asyncHandler in the utils folder of my project which I use across all files and use it in the async middlewares

utils.js contains

const asyncHandler = fn => (req, res, next) => { fn(req, res, next).catch(next) } 

other.js contains

async function someAuthAsyncFunction(req, res, next) { await callToOtherService() next() } 

app.js contains

app.use(utils.asyncHandler(other.someAuthAsyncFunction)) 

This is worked for me as I'm working with routes

S.Nakib has a great answer. I included the asyncHandler in the utils folder of my project which I use across all files and use it in the async middlewares

utils.js contains

const asyncHandler = fn => (req, res, next) => { fn(req, res, next).catch(next) } 

other.js contains

async function someAuthAsyncFunction(req, res, next) { await callToOtherService() next() } 

app.js contains

app.use(utils.asyncHandler(other.someAuthAsyncFunction)) 

This is worked for me as I'm working with routes and just a few middlewares are async

added 1 character in body
Source Link

S.Nakib has a great answer. I combined it with a more simple version of jfriend00's answer.: I included the asyncHandler in the utils folder of my project which I use across all files and use it in the async middlewares

utils.js contains

const asyncHandler = fn => (req, res, next) => { fn(req, res, next).catch(next) } 

other.js contains

async function someAuthAsyncFunction(req, res, next) { await callToOtherService() next() } 

app.js contains

app.use(utils.asyncHandler(other.someAuthAsyncFunction)) 

This is worked for me as I'm working with routes

S.Nakib has a great answer I combined it with a more simple version of jfriend00's answer. I included the asyncHandler in the utils folder of my project which I use across all files and use it in the async middlewares

utils.js contains

const asyncHandler = fn => (req, res, next) => { fn(req, res, next).catch(next) } 

other.js contains

async function someAuthAsyncFunction(req, res, next) { await callToOtherService() next() } 

app.js contains

app.use(utils.asyncHandler(other.someAuthAsyncFunction)) 

This is worked for me as I'm working with routes

S.Nakib has a great answer. I combined it with a more simple version of jfriend00's answer: I included the asyncHandler in the utils folder of my project which I use across all files and use it in the async middlewares

utils.js contains

const asyncHandler = fn => (req, res, next) => { fn(req, res, next).catch(next) } 

other.js contains

async function someAuthAsyncFunction(req, res, next) { await callToOtherService() next() } 

app.js contains

app.use(utils.asyncHandler(other.someAuthAsyncFunction)) 

This is worked for me as I'm working with routes

Source Link

S.Nakib has a great answer I combined it with a more simple version of jfriend00's answer. I included the asyncHandler in the utils folder of my project which I use across all files and use it in the async middlewares

utils.js contains

const asyncHandler = fn => (req, res, next) => { fn(req, res, next).catch(next) } 

other.js contains

async function someAuthAsyncFunction(req, res, next) { await callToOtherService() next() } 

app.js contains

app.use(utils.asyncHandler(other.someAuthAsyncFunction)) 

This is worked for me as I'm working with routes