Express.js - How to set a header to all responses Express.js - How to set a header to all responses express express

Express.js - How to set a header to all responses


Just use a middleware statement that executes for all routes:

// a middleware with no mount path; gets executed for every request to the appapp.use(function(req, res, next) {  res.setHeader('charset', 'utf-8')  next();});

And, make sure this is registered before any routes that you want it to apply to:

app.use(...);app.get('/index.html', ...);

Express middleware documentation here.