How to use the token function from morgan

Find comprehensive JavaScript morgan.token code examples handpicked from public code repositorys.

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" });
fork icon0
star icon0
watch icon1

+ 2 other calls in file

71
72
73
74
75
76
77
78
79
}

router.use(addRequestId)
// log server requests.
router.use(morgan('combined'))
morgan.token('url', (req) => {
  const { query, censored } = censorQuery(req.query)
  return censored ? `${req.path}?${qs.stringify(query)}` : req.originalUrl || req.url
})
fork icon0
star icon0
watch icon332

+ 15 other calls in file