title: Check for UNIQUE constraint in Node-Postgres
body: <p>I have put a UNIQUE constraint on the &quot;email&quot; column of my table and now in my Express API which is using Node-Postgres (pg), I want to make sure than the email that the user puts in when POSTing a student, isn't duplicated.</p>
  <p>My question is that how can I show a response like &quot;Email already taken!&quot; in my JSON object when that constraint gets violated?</p>
  <pre><code>const createStudent = (req, res) =&gt; {
    const { name, email, age, dob } = req.body;
    pool.query(insertStudent, [name, email, age, dob], (error, results) =&gt; {
       if (error) throw error;
       res.status(201).json({
         message: `Student Created Successfully!`,
         student: results.rows[0],
       });
    });
  };
  </code></pre>