question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can you load environment variables from an API and set them into config?

See original GitHub issue

From Romil Shah on Slack

I am not trying to set the process.env as it’s not compatible as per case. My setting variables are in form of JSON object along with nested too so It will not make sense to set in process.env as that will be similar to just key/value pair as flat level.

So I am trying to fetch the setting values from an api and setting it into a singleton constant object which can be accessible into various config files such as api.ts, sequelize.ts etc. With the previous version of actionhero this was working for me as I was loading the setting values with async request in boot.js but after upgration, with server.ts this is not working for me.

Because, all the config files are loaded first before server.ts, so I cannot set the singleton object from server.ts

What’s the process to do something async in `server.ts, set a process.env variable before the config is initialized?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
evantahlercommented, Jul 1, 2020

In https://github.com/actionhero/actionhero/pull/1511, I’ve changed the default import statement of Actionhero within server.ts to make it simpler to modify the env.

0reactions
evantahlercommented, Jul 1, 2020

Here’s an example project that shows how to modify process.env via an async function before importing Actionhero https://github.com/actionhero/example-with-custom-env

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Environment Variables and Secrets - Render
From your Render Dashboard, click on the service that you want to add the environment variable to. · Click on Environment in the...
Read more >
Loading environment variables in JS apps - DEV Community ‍ ‍
This short tutorial will explain one way of loading environment variables into your code when developing locally. The main benefit is that ...
Read more >
Settings and Environment Variables - FastAPI
Run the server¶ ... To set multiple env vars for a single command just separate them with a space, and put them all...
Read more >
How To Set Environment Variables - Twilio
To persist the environment variables across processes, you can store them in the user and/or machine registry using the setx command. # sets...
Read more >
Environment Variables in Next.js - Frontend Digest
Setting env vars locally. When developing locally, Next.js will load environment variables from a file called .env.local at the root of our project....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found