javascript - Setting default environment variables in Heroku -
i'm working on app connects third-party apis require use of app id , secret key.
i storing these values environment variables in heroku, don't need expose them in code.
if deploy heroku, use heroku's environment variables resolve these api credentials.
if i'm working on locally, want use config.js module, , lookup api credentials there. note: config.js file included in .gitignore these credentials never end in cloud.
the problematic code this:
var api_secret = process.env.api_secret || require('../../config.js').secret; when run locally, i've got no issues. meaning, unable resolve environment variable, instead uses secret within config.js.
when run on heroku, throw error telling me module 'config.js' not found. makes sense, because never pushed rest of repo, virtue in .gitignore.
because heroku parsing through code before ever runs, require('../../config.js') problematic. trying lookup file doesn't exist.
how can solve issue of using environment variables when deployed, , config.js module when running locally?
on heroku dashboard application, can set config variables. if have heroku toolbelt set on machine, can use:
heroku config:set api_secret=secret see this article more.
edit: think may have misunderstood question. suggest, if possible, using dotenv npm package set config variables locally.
if not, thing check config.js package in package.json file, because heroku use build dependencies.
Comments
Post a Comment