Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda