Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
Change app settings inside Express.js request

Is it good practice to change app settings inside request Express.js handler?

app.set('title', 'My Site')
var express = require('express')
var app = express()
app.set('title', 'My Site')

app.get('/somehow', function (req, res) {
  req.app.set('title', 'New title')
  res.send('hello world')
})

app.listen(3000)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Is it good practice to change app settings inside request Express.js handler?

It can be used just fine if what you're intending to do is to change a global server setting that could affect all future requests from all future clients. Typically, this would be done under some sort of administrative authentication (not by any random client) or just be some type of server metric you're accumulating.

It would not be the appropriate way of affecting one particular response (because it's affect is persistent and affects all future requests). For that, you should modify that one response locally, either manually or by using an HTML template. For passing data to templates, you can pass it directly or set it in res.locals and the template can render the page using that data.


If this is for business logic, then you generally do not want to make business logic dependent upon the Express framework as there's really no reason to make one dependent upon the other. Instead, you can implement a stand-alone module for your business logic that keeps track of its own state and exports an interface for getting/setting/implementing the business logic. It can then store state as module-level variables or in a database or in whatever is most appropriate.

Make this business logic a stand-alone module also makes it independently testable without Express, usable in other apps, simpler to debug, etc...

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda