---
# System prepended metadata

title: Add artist to database with MySQL2
tags: [solution, music-library, track]

---

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

# Add artist to database with MySQL2

```javascript=
exports.create = async (req, res) => {
  const db = await getDb();
  const { name, genre } = req.body;

  try {
    await db.query(`INSERT INTO Artist (name, genre) VALUES ('${name}', '${genre}')`);

    res.sendStatus(201);
  } catch (err) {
    res.status(500).json(err);
  }

  db.end();
};
```