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

135
Views
Response Time in node js

I have installed response-time on my development environment

main.ts

app.use(
    responseTime((req: any, res: any, time: any) => {
        console.log(`${req.method} ${req.url} ${time}`);
    })
);

And api.ts

router.post('/disconnect', async (req, res, next) => {
    .....
    next();
});

But the problem is console.log(${req.method} ${req.url} ${time}); is not displaying on console when i hit API endpoint? what am i missing

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Have you tried putting the response-time middleware assignment before the router assignment? As far as I can see the order makes a difference.

I've tested this out and the following trivial code works.

const express = require('express')
const responseTime = require('response-time')

const router = express.Router()
const app = express()

app.use(
    responseTime((req, res, time) => {
        console.log(`${req.method} ${req.url} ${time}`);
    })
);

app.use('/router/', router);

router.post('/disconnect', async (req, res, next) => {
    res.send('POST');
    next();
});

app.listen(3000);
 

If I do:

curl -X POST http://localhost:3000/router/disconnect

I see a log output like:

POST /disconnect 2.5177

But if I switch the order of the middleware like so:

app.use('/router/', router);

app.use(
    responseTime((req, res, time) => {
        console.log(`${req.method} ${req.url} ${time}`);
    })
);

I don't see any output at all.

about 4 years ago · Juan Pablo Isaza 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!