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

167
Visualizações
How to put timestamp in express js?

I tried putting timestamp for all my requests.I used morgan for that and i include like below,

if (process.env.NODE_ENV === 'development') {
    // Enable logger (morgan)
    app.use(morgan('common'));
  }

This results in my console as,

::ssss:197.7.8.1 - - [Fri, 28 Apr 2017 00:28:29 GMT] "GET /assets/jqwidgets/styles/images/icon-right.png HTTP/1.1" 200 143
::ssss:197.7.8.1 - - [Fri, 28 Apr 2017 00:28:29 GMT] "GET /assets/jqwidgets/styles/images/icon-left.png HTTP/1.1" 200 139
::ssss:197.7.8.1- - [Fri, 28 Apr 2017 00:28:31 GMT] "GET /admin-get-users

From the above results I i am getting the timestamp as well as the internet address(::ssss:197.7.8.10which i dont want.Can anyone please suggest me help.I f any new module suggested is also a good solution for me.Thanks.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You're asking for how to get the timestamp with Morgan, not expressjs. You should probably retag the question appropriately.

In any event, morgan offers some predefined tokens you use when constructing the object to set up the string it outputs. If you're only interested in the timestamp use app.use(morgan(':date[format]')); to construct the object where format is one of clf (prints like "27/Apr/2017:12:00:00 +0000", iso (prints like "2017-04-27T12:00:00.000Z"), or web (prints like "Thu, 27 Apr 2017 12:00:00 GMT"). Other tokens also exist like :status for the HTTP status code of the response or :url for the url of the request. if you find you're interested in logging those. After your comment it seems you are, so try app.use(morgan(':date[clf] ":method :url"')); or app.use(morgan(':date[clf] ":url"'));.

if (process.env.NODE_ENV === 'development') {
    // Enable logger (morgan)
    app.use(morgan(':date[clf] ":method :url"')); // prints date in same format as original Q
}
over 4 years ago · Santiago Trujillo 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