I have config server which is a containerized. now my task to create a API in express. the problem i am facing is how to read the common properties defined in the config server in my express api.
Create a .env File to store your environment variables. Example: .env.development or .env.test or .env.production files that you can put into a config folder.
Download the node module "node-foreman" https://github.com/strongloop/node-foreman
Now run your web server using foreman and specify which environment you want with the following command line command.
./node_modules/foreman/nf.js --env ./config/.env.development start web=1
That will load the correct environment that you want.
Then to access your environment variables in the actual code, you use "process.env".
For example if you have a key-value pair in your .env file like version=5.5 then to access it in the code you do process.env.version.
Related
I have created .env file to set environment variables as shown below:
Inside which I have given below mentioned code.
VUE_APP_BASEURL="https://qa-apps-nodejs.Dtech.com:9000/"
PORT=8080
I have written below code in my js file and executed npm install dotenv:
require('dotenv').config();
console.log(process.env.VUE_APP_BASEURL);
With the above code, I need to get https://qa-apps-nodejs.Dtech.com:9000/ in console. But instead I'm getting:
undefined
Just restart your server as newly created env variables are not available only after hot-reload you have to rebuild your application (restart your server). For reference you can look here
No need to install "dotenv" simply place .env file in the root of your project (at the same level of your package.json file) and Vue CLI will handle the reset. Side note; as of Vue CLI 3 only variables that start with VUE_APP_ will be loaded. make sure also to rerun npm run serve again to restart your server.
for more details: visit docs
Using the Serverless framework, I want to be able to change the AWS region from an envrionment variable.
provider:
name: aws
region: ${env:AWS_REGION}
Then, AWS_REGION can be set to eu-west-2.
However, I want to have that set in a .env file:
AWS_REGION=eu-west-2
And then have that .env read by Serverless.
There are many topics about setting variables in the serverless.yml file, and exporting them from that file, but I want to put them into the file.
Out of the box serverless doesn't parse .env, that part belongs to you.
I see three options for you:
Use the serverless-dotenv-plugin.
Write a script that exports .env vars to your local environment before you run serverless.
Run serverless in docker-compose which is .env aware -- I use this in combination with Makefile, even in a CI/CD context.
Serverless now supports .env files without the need for a plugin
Add useDotenv: true to your serverless.yml file. The variable should be at the root level, same as service: ...
Add a .env file at the root of your project and serverless will load the variables.
Example:
// .env
MY_TABLE=A_TABLE_NAME
use this plugin to write .env with serverless.yaml serverless-export-env. so you just need to overwrite your region inside serverless yaml, and your env will be generated based on whay you've written in serverless.yaml.
I am trying to use an environment variable in the odoo.conf
file to specify the path where the logs are stored.
So far I have tried:
logfile = ${test.rueda}/odoo.log
But it does not work.
Is there any way to achieve this?
The Odoo configuration files do not support access to environment variables.
I can think of 2 possible approaches:
Use relative paths. The file names in the configuration are relative to the working directory of the Odoo server process. Start the Odoo server in different directories, one for every purpose, and keep the same structure relative to that.
Use environment variables in the command line. When starting the Odoo server, any configuration option can be passed using -- (2 dash signs) as a prefix. In the start script, you can then use environment variables as in any other shell script.
See https://www.odoo.com/documentation/11.0/reference/cmdline.html for details.
For referencing files or path:
When i work without external disk (where i can find my datadir):
i use in odoo config file data_dir = my_absolute_path_in_my_local_disk.
This path have a symbolic redirection to where is my local physical location of my local data directory
When my external disk come back, i change the symbolic link:
my_absolute_path_in_my_local_disk -> my_external_disk_..._data
I'm trying to pass in a variable at runtime to my application to configure where my external config files are stored.
I need external config files so that the config can be changed without having to deploy a new release every time the config changes, and want to be able to define the location of these at run time so the applications is more portable and the team deploying the application can follow their existing rules on where to store config.
I have read answers like this:
How to add custom "-Djava" arguments to Grails app? - but I'm not sure how this relates to me from the point of having the war file on my local machine, to deploying this with the param being passed in. I have been using the Tomcat Web Application Manager to simply select the war file to upload, and clicking delpoy - the file is uploaded and automatically exploded out and launched.
https://grails.github.io/grails-doc/latest/ref/Command%20Line/war.html - This suggests that the arguments have to passed in at the point of creating the war file which is not what I'm after.
In my code I have:
grails.config.locations = ["${System.properties['configFolder']}/application-config.properties"]
and I am looking for a way to include arguments when deploying from the Application Manager, or a command something like
deploy myApp.war -DconfigFolder="/usr/share/tomcat5/.grails/myApp/conf/application-config.properties"
EDIT
Turns out you're meant to pass in the runtime parameters when you start the tomcat server (or just after), not when you deploy the application.
The command needed is:
export CATALINA_OPTS="-DconfigLocation=/usr/share/tomcat5/.grails/TAPaS/"
or whatever params/values you want.
This can either be entered manually once the server has been started, or you can create a setenv.sh file containing that command within the CATALINA_HOME directory. This can be found out using the echo $CATALINA_HOME. Another way to find it is to use the start command below, and view the response, e.g.
bash catalina.sh start
Using CATALINA_BASE: /opt/apache-tomcat-7.0.61
Using CATALINA_HOME: /opt/apache-tomcat-7.0.61
Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.61/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-7.0.61/bin/bootstrap.jar:/opt/apache-tomcat-7.0.61/bin/tomcat-juli.jar
If you have added the command to the setenv.sh file, use the command bash catalina.sh start to start the server. bash catalina.sh stop is used to stop it. You will need to use the path to .sh file if you're not in the directory of them.
As far as I can work out, this is not possible.
Whenever a .war file is dropped into the appBase
if autoDeploy attribute is "true" then the application will automatically be deployed while the Tomcat server is running
else, the application will be deployed when there Tomcat server is started
bash /opt/apache-tomcat-7.0.61/bin/shutdown.sh
bash /opt/apache-tomcat-7.0.61/bin/startup.sh
will shutdown and the start up the server again and any .war files that are in the appBase will be deployed.
The only instance I can see where an actual command is needed to deploy is when using the Client Deployer Package. More information on Tomcat Deployment found at: https://tomcat.apache.org/tomcat-8.0-doc/deployer-howto.html
I'd like my API's base URL to change from dev to prod. In Angular I user to use a config.json file which was later injected into the app using grunt-env
If you use the Aurelia CLI, it will generate an environments directory inside of your aurelia_project.
Within this directory you can setup environmental configs that will be copied into environment.js in your src directory based the --env [dev/stage/prod] flag that you pass into your au build/run commands.
Then you can use import environment from './environment' to access your environment specific configuration values.
Another option that you can look into is the Aurelia Configuration Plugin, which also has dynamic environmental configs.
If you want to 'inject' it only once then what is stopping you from using a simple ES6 module ? It should be loaded only once from the server.
For instance you could something like that in a config.js file : (warning ! I didn't try to run it)
export var Config = {
path : 'path to find'
};
you can then use your module anywhere you need it :
import {Config} from 'config';
I have successfully used the Aurelia-Configuration plugin to dynamically switch environments based on the domain that hosts the app
More info https://github.com/Vheissu/Aurelia-Configuration/blob/master/README.md#get-started to do this