1.

How To Config Properties In Express Application?

Answer»

In an EXPRESSJS Application, we can config properties in following two ways:

With Process.ENV:

  • Create a file with name ‘.env’ INSIDE the PROJECT folder. 
  • Add all the properties in ‘.env’ file. 
  • In server.js any of the properties can be used as:

    var host = process.env.APP_HOST
    app.set('host', host);
    logger.info('Express server listening on http://' + app.get('host'));

With RequireJs:

  • Create a file called ‘config.json’ inside a folder called ‘config’ inside the project folder.
  • Add config properties in config.json.

    {
    "env":"development", "apiurl":"http://localhost:9080/api/v1/"
    }
  • Use require to access the config.json file.

    var config = require('./config/config.json');

In an ExpressJS Application, we can config properties in following two ways:

With Process.ENV:

With RequireJs:



Discussion

No Comment Found