Response

See here

Implemented methods

  • send

  • pipe

  • json (same as send, but for compatibility we keep this method)

  • sendFile

  • redirect

  • status

  • writeHead

  • cookie

  • setCookie

  • hasCookie

  • removeCookie

  • setHeader

  • getHeader

  • hasHeader

  • removeHeader

  • setHeaders

  • writeHeaderValues

  • writeHeaders

  • type

  • header

Examples

app.get('/is_logged', async (req, res) => {
  const status = res.hasCookie('userId') ? 'success' : 'error';

  return res.send({ status });
});

Redirect + Params example

app.get('/user/:id/login', async (req, res) => {
  const { id } = req.params;

  const result = await db.getUser(id);

  return res.redirect(`/user/${id}/`);
});

sendFile

File should be on the same path where JS file is or you can try Absolute path for stream/sendFile

app.get('/video.mp4', async (req, res) => {
  return res.sendFile('video.mp4');
});

Last updated