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

137
Visualizações
Static files not reading the .env file in a node js serve

I have a react app that I was able to build into static files which I then added to my node js app. after installing dotenv and adding require('dotenv').config() to server.js in the node server application. The following piece of code I had in the react application does not seem to be working now although the static files are being rendered in the browser just fine.

let node_server_url;
//TODO
// set the NODE_ENV on the .env file.
// create the .env file on the root of the project and add a NODE_ENV on the file
// e.g NODE_ENV=development or NODE_ENV=production

let urlConfig = (process.env.NODE_ENV === "production") ? {
    urlBackend: `https://mybluebookloanuat.bayportbotswana.com`,
} : {
    // urlBackend: `http://10.16.32.22:5000`,
    urlBackend: `http://localhost:5003`,
}

// eslint-disable-next-line
export default node_server_url = urlConfig.urlBackend;

server.js:

require('dotenv').config()
...
const app = express();

// for parsing request body
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

// cross origin access to allow backend to communicate with frontend
app.use(cors());

const db = require("./app/models/index");
// to drop existing database and resync the database
db.sequelize.sync({force: false})

require("./app/routes/loan_application.routes")(app);


app.use(express.static(path.resolve(__dirname, 'assets')))

app.get('*', (req, res) => {
 res.sendFile(path.resolve(__dirname, 'assets', 'index.html'));
});

I want to be able to just set up in the .env file the address for development and for production in the node server app. Can someone help me?

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