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

172
Views
How to get the response time in node js

Recently I started putting response time to my API's.I tried putting to my routes but I am not sure how to use it.My aim is to get the response time in the console for each request.

var responseTime = require('response-time')
app.use(responseTime());
app.route('/getAllUsers').get(users.getUsers); 

Can anyone please suggest help.Thanks.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

For getting the response time in your routes -

var start = new Date();

router.get('/dummy', function(req, res, next){
    console.log('Request took:', new Date() - start, 'ms');
});

output ex - Request took: 1596 ms

about 4 years ago · Santiago Trujillo Report

0

You can pass a function that will get called after a request:

app.use(responseTime((req, res, time) => {
  console.log(req.method, req.url, time + 'ms');
}));

Or use a more elaborate logger middleware like morgan that also provides the option to log response times.

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!