Closed Mohammadreza99A closed 3 years ago
Hey there. Yes, this can be done with an npm package that is called express-async-errors. You can check it out here: https://www.npmjs.com/package/express-async-errors
npm i express-async-errors
And then you will have to add it in your app.js file like this:
const express = require('express');
require('express-async-errors');
const User = require('./models/user');
const app = express();
app.get('/users', async (req, res) => {
const users = await User.findAll();
res.send(users);
});
I want to know if there is a way to get rid of
catchAsync
function inutils
? At the moment, this function wraps the controller methodes.