My Profile Photo

Rich Werden

A simple site for Rich to write about code and archive some completed projects for future reference...

#TIL: Handling GET and POST on the same endpoint

Today’s TIL: You can use app.route() for handling both GET and POST requests on the exact same endpoint in Express: Just chain them together after using app.route('/endpoint') like so…

  .get(function (req, res) {    res.send('Get a thing')  })
  .post(function (req, res) {    res.send('Add a thing')  })
  .put(function (req, res) {    res.send('Update a thing')  })

Keepin’ it clean…