express-async-errors 1


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();  

Here is what the above code is Doing:
1. We’re importing the express-async-errors module.
2. We’re importing the User model.
3. We’re creating a GET route that returns all users.
4. We’re using the async/await syntax to make the code more readable.
5. We’re calling the findAll() method on the User model.
6. We’re sending the users back to the client.

Now, let’s say that the findAll() method throws an error.

Similar Posts