How do I make a node app load variables from .env?
-
I am testing some things with a custom node app for Cloudron, one of these tests is making my app load environment variables from my .env file, I've tried setting variables from cloudron cli and it worked, but for my application I really do need to load them from a file.
What I've tried:
Setting dotenv path manually in my server.js file as
require('dotenv').config({ path: '../data/.env' })But did not work, also tried at the start.sh when node is called as
node -r dotenv/config your_script.js dotenv_config_path=../data/.envDid not work either, my program was not able to load my file and when my code ran
console.log(process.env)I was only getting the cloudron variables such as CLOUDRON_API_ORIGIN, PATH, CLOUDRON_APP_HOSTNAME,
CLOUDRON and many others.So, my question is, how do I make my nodejs app load my environment variables from a .env file located in the /app/data folder? If that is even possible.
I tried searching for that here on the forum but I could not find an answer for that specific problem.
-
I am testing some things with a custom node app for Cloudron, one of these tests is making my app load environment variables from my .env file, I've tried setting variables from cloudron cli and it worked, but for my application I really do need to load them from a file.
What I've tried:
Setting dotenv path manually in my server.js file as
require('dotenv').config({ path: '../data/.env' })But did not work, also tried at the start.sh when node is called as
node -r dotenv/config your_script.js dotenv_config_path=../data/.envDid not work either, my program was not able to load my file and when my code ran
console.log(process.env)I was only getting the cloudron variables such as CLOUDRON_API_ORIGIN, PATH, CLOUDRON_APP_HOSTNAME,
CLOUDRON and many others.So, my question is, how do I make my nodejs app load my environment variables from a .env file located in the /app/data folder? If that is even possible.
I tried searching for that here on the forum but I could not find an answer for that specific problem.
-
G girish marked this topic as a question on
-
G girish has marked this topic as solved on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login