title: On node how to you perform an insert if doesn't exists
body: <p>My rest api calls Put request to this function to create firebase token on Postgre-sql.<br> However, I realized whenever the token gets refreshed a new row will be added for the same user. <br>How do I make it so that it'll perform a insert if it exists and updates if it doesn't.<br> I've already tried on conflict update, but it doesn't work.</p>
  
  <p>The code is here : </p>
  
  <pre><code>function createUserToken(req, res, next) {
    var userid = req.user.email;
    db.none('insert into fcmdb(userid, token)'+
      'values($1, $2) on conflict update',
      [userid,req.body.token])
      .then(function () {
        res.status(200)
          .json({
            status: 'success',
            message: 'Inserted token'
          });
      })
      .catch(function (err) {
        return next(err);
      });
  }
  </code></pre>