I've created a file called .elasticbeanstalk/environment.config with the following in it:
option_settings:
- option_name: NODE_ENV
value: development
I'm also passing the process.env.NODE_ENV to the view so I can check the value
app.get('/', function(req, res) {
var data = {
env: process.env.NODE_ENV
}
res.render('upload',data);
});
On my local machine I get the value "local" which is what I've set it to. When I deploy to Amazons Elastic Beanstalk via $ git aws.push
the value is empty.
Is there anything else I need to do for EB to recognise the NODE_ENV setting?
NODE_ENV is an environment variable that stands for node environment in express server. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production).
Use echo $NODE_ENV . The command line is a shell, probably bash and that's the bash syntax to print the value of an environment variable.
Jest automatically defines environment variable NODE_ENV as test (see https://jestjs.io/docs/environment-variables), as you can confirm from your error message: console.
Your .config file should be located in the .ebextensions
directory, not .elasticbeanstalk
.
Try it then, if that doesn't work, you can always use the console.
In the meantime, you can always use the Elastic Beanstalk Console which let's you add environment variables from its interface. To do so, just:
Other ways to set environment variables
in elastic beanstalk are -
Create a config file in .ebextensions
directory like environmentalvar.config
and define variables in option_settings
and include this file into application bundle. (Aws Documentation)
example -
option_settings:
aws:elasticbeanstalk:application:environment:
NODE_ENV: production
By using elastic beanstalk command line tool. Command for set variable-
eb setenv VAR_NAME=VAR_VALUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With