---
# System prepended metadata

title: Read all artists from database and return to user
tags: [solution, music-library, track]

---

---
tags: music-library,solution,track
---

# Read all artists from database and return to user

```javascript=
// src/controllers/artist.js
...

exports.read = async (_, res) => {
  const db = await getDb();

  try {
    const [artists] = await db.query('SELECT * FROM Artist');

    res.status(200).json(artists);
  } catch (err) {
    res.status(500).json(err);
  }
  db.end();
};

...
```

```javascript=
// src/routes/artist.js
...
router.get('/', artistController.read);
...
```
