config undefined in environment specific configuration files
In your development.rb it should have a block that looks like:
YourApplicationName::Application.configure do
config.active_support.deprecation = :log
config.cache_classes = false
end
The config lines must be placed inside that block.
process.env variable returns undefined from a specific file
Have you imported dotenv at the top of your dev.js file as well? That solved it for me when I tried it locally.
How to store Node.js deployment settings/configuration files?
Much later, I found a pretty good Node.js module for managing configuration: nconf.
A simple example:
var nconf = require('nconf');
// First consider commandline arguments and environment variables, respectively.
nconf.argv().env();
// Then load configuration from a designated file.
nconf.file({ file: 'config.json' });
// Provide default values for settings not provided above.
nconf.defaults({
'http': {
'port': 1337
}
});
// Once this is in place, you can just use nconf.get to get your settings.
// So this would configure `myApp` to listen on port 1337 if the port
// has not been overridden by any of the three configuration inputs
// mentioned above.
myApp.listen(nconf.get('http:port'));
It also supports storing settings in Redis, writing configuration files, and has a fairly solid API, and is also backed by one of the more well-respected Node.js shops, Nodejitsu, as part of the Flatiron framework initiative, so it should be fairly future-proof.
Check out nconf at Github.
Laravel 5.4 environment based config files
One option could be to use a service provider. If you're only going to be overriding one or two values then you might as well just use your AppServiceProvider
, otherwise I would suggest creating a new service (e.g. ConfigServiceProvider
).
In the boot()
method of your service provider you could add something like:
if (app()->environment() === 'local') {
config()->set('contants.api_url', 'http://example.com');
}
Unable to open rails console
It's probably a mis-configuration in your config/environment.rb file!
Double check that the syntax of that file is correct
Also:
config undefined in environment specific configuration files
React Native - .ENVs are undefined in Metro Bundler's config file when bundling iOS apps
I don't know why, but it seems like Metro overwrites set ENVs when bundling iOS apps.
Elsewhere ENVs are defined.
If anyone comes over this problem, this is how I solved it.
Solution
1. In the generate-config.js
script that is in NPM scrips above, I have added NODE_ENV checks. The script generates the config.js
inside the public folder, based on NODE_ENV.
const fs = require("fs");
console.log( process.env.NODE_ENV);
if(process.env.NODE_ENV === 'production'){
fs.copyFile("config.runtime.js","public/config.js",(err) => {if(!err){console.log(err)}});
} else if (process.env.NODE_ENV === 'mock'){
fs.copyFile("config.mock.js","public/config.js",(err) => {if(!err){console.log(err)}});
} else {
fs.copyFile("config.debug.js","public/config.js",(err) =>{if(!err){console.log(err)}});
}
2. I have imported generated config.js
into Metro.config and used it as needed.
const config = require(path.resolve(__dirname, 'public/config.js'));
config.js for reference:
module.exports = {
isProduction : false,
disableCache: true,
API:"http://alanj.bs.local:15455/",
/////////////////////////////////////
// ENVs
/////////////////////////////////////
MOCKED_BACKEND: 1,
/////////////////////////////////////
}
Error HH8: There's one or more errors in your config file: * Invalid value undefined for HardhatConfig.networks.rinkeby.url - Expected a value of t
Could be a few things here but if you're using create-react-app
your .env
variables need to be prefixed with REACT_APP
. So by example your env variable STAGING_ALCHEMY_KEY
should be REACT_APP_STAGING_ALCHEMY_KEY
. If you use webpack
you might need to make some modifications in here as well. Hope this helps.
NodeJS environment variables undefined
This needed to be in the root directory of my project.
nodemon.json
{
"env": {
"MONGO_ATLAS_PW": "xxxx",
"JWT_KEY": "secret_this_should_be_longer"
}
}
Related Topics
How to 'Join' an Array Adding to the Beginning of the Resulting String the First Character to Join
Why Does Trying to Use Grape with Rails Fail with "Uninitialized Constant API"
Bundler How to Uninstall Conflicting Dependency
How to Dry Up Method with Multiple { 'Not Found' }
Where Are Catch and Throw Useful in Ruby
Where Does Rails Store Data Created by Saving Activerecord Objects During Tests
Ruby Open-Uri Can't Open Url (M1 MAC)
How to Check If a Resource Exists in an Aws S3Bucket
In Ruby How to Create a Local Variable Explicitly
Jekyll Liquid - Accessing _Config.Yml Dynamically
How to Split a String of Repeated Characters with Uneven Amounts? Ruby
404 Resource Not Found: Domain with Google Directory API
Ruby 1.8: Hash#Sort Not Return Hash But Array (Better Way to Do This)
Defined' and 'Unless' Not Working as Expected
Can Anyone Explain This Array Declaration to Me