how to setup multiple paths in user environmental variables in windows 10 - node.js

I want to set up multiple paths in the user environmental variables in windows 10. but can only set a single path, how to overcome this issue?

If you want to add user defined environment variable then use react-native-config library. So in short if there are variables defined in .env file then you can use it anywhere in the react-native app like below:-
.env file
API_URL = "https://baseurl/endpoint"
//To use the above environment variable
import config react-native-config
function apiCall() { axios(config) }
With the help of react-native-config you can use environment variable in native code also and vise-versa.
For better use define .env.staging file. By default config lib finds .env file. To run the application with .env.staging file see below command.
$ ENVFILE=.env.staging react-native run-ios # bash
$ SET ENVFILE=.env.staging && react-native run-ios # windows
$ env:ENVFILE=".env.staging"; react-native run-ios # powershell
For more information checkout :- https://github.com/luggit/react-native-config
Happy coding mate :)

to add multiple paths for a single environment variable, list them all with a semicolon(";") in between like that:
C:\Cpp_Headers\pybind11;C:\Cpp_Headers\cpython\Include;C:\Users\admin\Cpp_Headers\cpython\PC
(and so forth). From this input Windows will automatically recognize multiple definitions.

Related

Using dotenv in cloud run

I have created a .env file in my local system while developing a project. If I upload my project along with .env file, will it work fine or do i have to assign env variables separately?
According to the documentation it won't work like that.
You can set them in Console or provide with --set-env-vars flags during deployment from command line or set id Dockerfile with ENV parameter.

Build variables not accessible in my react native app

I need to inject env variables into my code.
I'm using azure pipelines to build my android app in react native.
I have set env variables in the build configuration and I have created a file called appcenter-post-clone.sh. The contents of this file are as follows:
ENV ADMIN_HOST= $ADMIN_HOST
And in my build configuration I have defined
ADMIN_HOST = https://example.com.
But I'm getting this error, [command]/bin/bash /Users/runner/runners/2.160.1/work/1/s/appcenter-post-clone.sh
ENV: https://example.com: No such file or directory. What I fail to understand here is, why is azure treating the value of my env variables as a file? How do I make this work?
The blunder I made here is, I should have used
ENV ADMIN_HOST=$ADMIN_HOST
Without the space. That solved it for me.

NodeJS Google Vision is unable to detect a Project Id in the current environment

Under Ubuntu environment, NodeJS Google Vision complains:
Error: Unable to detect a Project Id in the current environment.
Even though I already put json credential through
$ export GOOGLE_APPLICATION_CREDENTIALS=/var/credential_google.json"
Please help.
As a quick hack you can try this :
$ GOOGLE_APPLICATION_CREDENTIALS="/var/credential_google.json" node app.js
It's not recommended to use a .json config file locally. I've seen these leak on production servers causing whole platforms to be deleted + the introduce environmental switching and security issues.
Setup Google Cloud CLI.
Now the server will 'look' at the local environment and use that.
If you get the error "Unable to detect a Project Id in the current environment.", it means the auth library cannot find the project default id.
You need to have a base project in Google Cloud set, regardless of environmental variables and project you're running.
Run
gcloud config set project [some-project-id]
Now if you run (node example)
"dev": "NODE_ENV=dev GCP_PROJECT=some-project-id nodemon index.ts",
It will load the project environment. This also allows you to deploy easier with:
"deploy:dev": "y | gcloud app deploy --project some-dev-project app.yaml",
"deploy:prod": "y | gcloud app deploy --project some-prod-project app.yaml"
App engine has security setup automatically with standard environments. With flex you can use one of the manage images Google Provides.
If you are usually a windows user and trying out Ubuntu (like me), the problem is likely with the assumptions that the export command exports variable to all terminal sessions and that you need to open a new terminal to get it to use (as expected in a windows terminal for an environment variable).
The export command doesn't export the variable to another terminal session. So if you export it in a terminal, you use it on the same terminal.
If you would like to export it permanently, then you can try the solution listed here
You can put the path to the JSON credentials directly when instantiating the client, by passing it as an argument.
For example:
const client = new speech.SpeechClient( {keyFilename: "credential_google.json"});
Also, for me setting it in the terminal didn't work.

How to interpolate environment variables within netlify.toml config

I want to proxy to a different api depending on the environment - I've tried a few variations on the following theme without any luck. What's the correct way of doing this, if its even possible?
[build.environment]
API_URI="https://dev-api.foo.com/:splat"
[context.production.environment]
API_URI="https://prod-api.foo.com/:splat"
[[redirects]]
from = "/api/*"
to = "$API_URI"
status = 200
force = true
This does not work.
Although the above config works when I hardcode a URI into the to field, it just fails when I try to interpolate an env var.
It's not supported, but Netlify suggest a work-around in their documentation (https://www.netlify.com/docs/netlify-toml-reference):
Using Environment Variables directly as values ($VARIABLENAME) in your
netlify.toml file is not supported. However, the following workflow
can be used to substitute values based on environment variables in the
file, assuming you are only trying to change headers or redirects. The
rest of the file is read BEFORE your build - but those sections are
read AFTER the build process.
Add a placeholder like
API_KEY_PLACEHOLDER somewhere in the netlify.toml redirects or headers
sections.
Create an Build Environment Variable, for example API_KEY,
with the desired value. You can do this in the toml file or in our UI
in the Build and Deploy Settings section of your configuration. You
might use the latter to keep sensitive values out of your repository.
Add a command like this one to your build command: sed -i
s/API_KEY_PLACEHOLDER/$API_KEY/g netlify.toml && normal build command.
Answering my own question - it's not supported, you have to manually interpolate env vars yourself as part of the build on Netlify.
Yes. It's possible. Here is the detailed docs: https://www.netlify.com/docs/continuous-deployment/#deploy-contexts
In my case, I need to set a REACT_APP_API_URL separate for production and all other branches. Here is what I use:
[context.production.environment]
REACT_APP_API_URL = "https://api.test.im"
[context.deploy-preview.environment]
REACT_APP_API_URL = "https://api-staging.test.im"
[context.branch-deploy.environment]
REACT_APP_API_URL = "https://api-staging.test.im"

How can I set NODE_ENV variable for ironworker (iron.io) task?

Is there a way to set/configure NODE_ENV for an ironworker task? It's not set in the process.env output. Because of that the config module loads config/development.json configuration file.
There are a couple ways to set this value. First you can send ENV params with the -e flag, as noted here https://github.com/iron-io/dockerworker/tree/master/node#2-test-locally
Iron actually recommends that you provide this information as part of the configuration and payload when creating a task.
The way Iron recommends doing this is a bit annoying (http://dev.iron.io/worker/reference/configuration-variables/#config-via-file):
Upload a config.json/yml file by specifying --config-file when uploading the code via the iron cli
Read the path to this config file via the CONFIG_FILE environment variable inside the container
Read the contents of this file, and parse them as JSON
I have another method which is easier: using arguments to npm start:
In your Node code, read the environment via env = process.argv[2] || process.env.NODE_ENV
Pass npm start -- <env> as the run command to the iron cli

Resources