Manage urls on a system

Asked

Viewed 30 times

1

I’m on a project where there’s the test environment, and the production environment.

When I am developing in test, I use some different urls for this. I use some Amazon services, and they are different from the production urls.

However, it is very annoying to stay manually, changing the urls, I wonder if there is any good practice to manage this.

1 answer

1


You can check inside the application which environment, ie whether you are in production or development.

With the express it would be something like this:

var app = express();
if (app.get('env') === 'production') {
    // setar variáveis de produção
} else {
    // setar variáveis de desenvolvimento
}

In native Node.js would be:

if (process.env.NODE_ENV === 'production') {
    // setar variáveis de produção
} else {
    // setar variáveis de desenvolvimento
}
  • That one app.get('env'). Where does it come from? How do I let him know it’s production ? @Sergio

  • @Jonathan O app.get('env') is express.js API and this method returns the environment the application is running in. By default it is "Development" but if the production environment is set it returns "Production".

  • You think right inside the if me make a var config = require('./config1'); and in the else do var config = require('./config2'); ? That is, leave no if, the responsibility to perform a require.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.