Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
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.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

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
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!