DEV Community

Nimrod Munatsi
Nimrod Munatsi

Posted on

Static files not reading the .env file in a node js server

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 peice 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;
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)