My Libs need to access the environments variables inside the Apps
See original GitHub issueHi guys. My repository has three projects on the apps
folder. Each project has a self environment file. I have a service folder on the libs
folder with some services. These services need to use the environment variables of each project in your methods. Bellow, I will show the code…
Code
Env file on lp
project:
API_URL = https://URL/
AUTHORIZATION = CODE
ORIGIN_CODE = CODE
Env file on modal
project:
API_URL = https://ANOTHER_URL/
AUTHORIZATION = ANOTHER_CODE
ORIGIN_CODE = ANOTHER_CODE
An example of service:
export const fetchData = async (params: IData) => {
try {
const url = `${API_URL}path/`;
const data = (await axios.post(url, params)).data;
return data;
} catch (err) {
throw err;
}
}
The problem is, all projects will have to use the services, so, I need to pass on services the env variables. How can I do this?
I try this:
export const fetchData = async (env: IEnvironments, params: IData) => {
try {
const url = `${env.API_URL}path/`;
let data = (await axios.post(url, params)).data;
} catch (err) {
throw err;
}
}
The problem is, I need to pass the env variable in all methods calls. It’s ok? The NX has a better choice?
Regards.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
best practices to share environment variables with lib modules
I have 3 Angular apps in an Nx project that share some common environment variables. A public site, a private portal, and an...
Read more >Use environment variables in solutions - Power Apps
On the command bar, select New > More, and then select Environment variable. On the right pane, complete the following columns, and then...
Read more >Environment Variables: What They Are and How To Use Them
User environment variables are those that are local to a user profile in Windows systems. These variables are used to store user-specific ...
Read more >Manage Shared Libraries with Environment Variables
You can call directly to the toolA.exe , the required environment variables to locate both the executable and the shared libraries are automatically...
Read more >Passing environment variables to angular library
I have 3 Angular apps in an Nx project that share some common environment variables. A public site, a private portal, and an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here’s one way to do it. In my opinion your libraries should not be aware of environments. In the code below the “fetchData” is created somewhere in the application lp, and shared within lp. All usages in lp will point to this one function which in turn uses the library.
It is not really a question of NX here, but more of programming practices.
Forget my last message, I solved the question 😃