--- tags: music-library,solution,track --- # Getting an artist by id with pg ```javascript= // src/controllers/artist.js ... const getArtistById = async (req, res) => { try { const { id } = req.params const { rows: [ artist ] } = await db.query('SELECT * FROM Artists WHERE id = $1', [ id ]) if (!artist) { return res.status(404).json({ message: `artist ${id} does not exist` }) } res.status(200).json(artist) } catch (err) { res.status(500).json(err.message) } } module.exports = { ..., ..., getArtistById } ... ``` ```javascript= // src/routes/artist.js ... router.get('/:id', artistController.getArtistById); ... ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up