Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
How to log user input with Morgan?

Good morning,

I am trying to log user input from user when using morgan and express. What I am specifically trying to log is noted in this image: (The user posted a request with an object that includes two key/value pairs "name" and "number")

Image of logger

How would I go about logging this? Custom tokens or is there a predefined method I could use?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I found the solution, very simple:

app.use(express.json())

morgan.token("code", function getCode(req) {
  return JSON.stringify(req.body);
 });

app.use(morgan(':method :url :response-time :code'))

JSON.stringify(req.body) was what I was looking for!

about 4 years ago · Juan Pablo Isaza Relatório

0

Use this to write logs to a file:

// create a write stream (in append mode)
var accessLogStream = fs.createWriteStream(path.join(__dirname, 'access.log'), { flags: 'a' })

// setup the logger
app.use(morgan('combined', { stream: accessLogStream }))

You can find further references at the official Morgan documentation on how to write logs to a file

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda