How to use morgan

Comprehensive morgan code examples:

How to use morgan.token:

64
65
66
67
68
69
70
71
72
73
74
  res.status(404).end();
});


app.post("/api/persons", (req, res) => {
  const body = req.body;
  morgan.token("body", (req, res) => JSON.stringify(req.body));
  if (!body.name || !body.number) {
    res.status(400).json({ error: "malformed request body" });
  } else if (persons.find((p) => p.name === body.name)) {
    res.status(400).json({ error: "name must be unique" });