How to use multiple .env files like .env.development with Express.jsWriting files in Node.jsHow do I pass command line arguments to a Node.js program?How to access environment variable values?How to decide when to use Node.js?How to exit in Node.jsHow do I delete an exported environment variable?How to get GET (query string) variables in Express.js on Node.js?What is Express.js?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?can't access .env with node-config
Replacing cord for IBM model M keyboard
Can you cure a Gorgon's Petrifying Breath before it finishes turning a target to stone?
I transpose the source code, you transpose the input!
How to level a picture frame hung on a single nail?
What organs or modifications would be needed to have hairy fish?
How do I automatically add linebreaks "\" to the end of each row of a tabular environment?
Avoiding dust scattering when you drill
How to say "respectively" in German when listing (enumerating) things
Windows 10 deletes lots of tiny files super slowly. Anything that can be done to speed it up?
How do I introduce dark themes?
Would a 737 pilot use flaps in nose dive?
Diminished data rate with logic output optoisolator
How to identify whether a publisher is genuine or not?
Worlds with different mathematics and logic
Why most footers have a background color has a divider of section?
Calculate the Ultraradical
How to bring home documents from work?
Can an energy drink or chocolate before an exam be useful ? What sort of other edible goods be helpful?
To what degree did the Supreme Court limit Boris Johnson's ability to prorogue?
Incomplete iffalse: How to shift a scope in polar coordinate?
Is there an in-universe explanation of how Frodo's arrival in Valinor was recorded in the Red Book?
does 'java' command compile the java program?
GPLv3 forces us to make code available, but to who?
How big would the ice ball have to be to deliver all the water at once?
How to use multiple .env files like .env.development with Express.js
Writing files in Node.jsHow do I pass command line arguments to a Node.js program?How to access environment variable values?How to decide when to use Node.js?How to exit in Node.jsHow do I delete an exported environment variable?How to get GET (query string) variables in Express.js on Node.js?What is Express.js?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?can't access .env with node-config
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to use seperate .env files for each mode (development, production, etc...). When working on my vue.js projects, i can use files like .env.development or .env.production to get diffenent values for the same env key. (example: in .env.development: FOO=BAR and in .env.production: FOO=BAZ, in development mode process.env.FOO would be BAR, in production i'd be BAZ).
I'm working on an Express server and want to use these same kinds of .env files to store the port, db uri, user, pwd...
I know i can edit the scripts in package.json like
"scripts":
"start": "NODE_ENV=development PORT=80 node ./bin/www",
"start-prod": "NODE_ENV=production PORT=81 node ./bin/www"
but this gets messy when using multiple variables.
I've tried using dotenv but it seems like you can only use the .env file. Not .env.development and .env.production.
Can i use the dotenv package or do i need another one? Or could i do this withouth any package at all?
node.js express environment-variables dotenv
add a comment
|
I want to use seperate .env files for each mode (development, production, etc...). When working on my vue.js projects, i can use files like .env.development or .env.production to get diffenent values for the same env key. (example: in .env.development: FOO=BAR and in .env.production: FOO=BAZ, in development mode process.env.FOO would be BAR, in production i'd be BAZ).
I'm working on an Express server and want to use these same kinds of .env files to store the port, db uri, user, pwd...
I know i can edit the scripts in package.json like
"scripts":
"start": "NODE_ENV=development PORT=80 node ./bin/www",
"start-prod": "NODE_ENV=production PORT=81 node ./bin/www"
but this gets messy when using multiple variables.
I've tried using dotenv but it seems like you can only use the .env file. Not .env.development and .env.production.
Can i use the dotenv package or do i need another one? Or could i do this withouth any package at all?
node.js express environment-variables dotenv
1
Welcome to Stack Overflow. Why would you need multiple environment files on one host? Normally your development and production environments are on different hosts. (dev on your computer and production in the cloud for example).
– Varcorb
Mar 28 at 20:18
npmjs.com/package/dotenv#should-i-have-multiple-env-files
– lifeisfoo
Mar 28 at 20:24
add a comment
|
I want to use seperate .env files for each mode (development, production, etc...). When working on my vue.js projects, i can use files like .env.development or .env.production to get diffenent values for the same env key. (example: in .env.development: FOO=BAR and in .env.production: FOO=BAZ, in development mode process.env.FOO would be BAR, in production i'd be BAZ).
I'm working on an Express server and want to use these same kinds of .env files to store the port, db uri, user, pwd...
I know i can edit the scripts in package.json like
"scripts":
"start": "NODE_ENV=development PORT=80 node ./bin/www",
"start-prod": "NODE_ENV=production PORT=81 node ./bin/www"
but this gets messy when using multiple variables.
I've tried using dotenv but it seems like you can only use the .env file. Not .env.development and .env.production.
Can i use the dotenv package or do i need another one? Or could i do this withouth any package at all?
node.js express environment-variables dotenv
I want to use seperate .env files for each mode (development, production, etc...). When working on my vue.js projects, i can use files like .env.development or .env.production to get diffenent values for the same env key. (example: in .env.development: FOO=BAR and in .env.production: FOO=BAZ, in development mode process.env.FOO would be BAR, in production i'd be BAZ).
I'm working on an Express server and want to use these same kinds of .env files to store the port, db uri, user, pwd...
I know i can edit the scripts in package.json like
"scripts":
"start": "NODE_ENV=development PORT=80 node ./bin/www",
"start-prod": "NODE_ENV=production PORT=81 node ./bin/www"
but this gets messy when using multiple variables.
I've tried using dotenv but it seems like you can only use the .env file. Not .env.development and .env.production.
Can i use the dotenv package or do i need another one? Or could i do this withouth any package at all?
node.js express environment-variables dotenv
node.js express environment-variables dotenv
asked Mar 28 at 20:08
JonasJonas
85 bronze badges
85 bronze badges
1
Welcome to Stack Overflow. Why would you need multiple environment files on one host? Normally your development and production environments are on different hosts. (dev on your computer and production in the cloud for example).
– Varcorb
Mar 28 at 20:18
npmjs.com/package/dotenv#should-i-have-multiple-env-files
– lifeisfoo
Mar 28 at 20:24
add a comment
|
1
Welcome to Stack Overflow. Why would you need multiple environment files on one host? Normally your development and production environments are on different hosts. (dev on your computer and production in the cloud for example).
– Varcorb
Mar 28 at 20:18
npmjs.com/package/dotenv#should-i-have-multiple-env-files
– lifeisfoo
Mar 28 at 20:24
1
1
Welcome to Stack Overflow. Why would you need multiple environment files on one host? Normally your development and production environments are on different hosts. (dev on your computer and production in the cloud for example).
– Varcorb
Mar 28 at 20:18
Welcome to Stack Overflow. Why would you need multiple environment files on one host? Normally your development and production environments are on different hosts. (dev on your computer and production in the cloud for example).
– Varcorb
Mar 28 at 20:18
npmjs.com/package/dotenv#should-i-have-multiple-env-files
– lifeisfoo
Mar 28 at 20:24
npmjs.com/package/dotenv#should-i-have-multiple-env-files
– lifeisfoo
Mar 28 at 20:24
add a comment
|
1 Answer
1
active
oldest
votes
I've tried using dotenv but it seems like you can only use the .env file. Not .env.development and .env.production.
Not true -- see the path
option.
For example, require('dotenv').config( path: `/path/to/.env.$process.env.NODE_ENV` )
For anyone else: i finally went with this:const path = require('path'); require('dotenv').config( path: path.join(__dirname,
../.env.$process.env.NODE_ENV));
– Jonas
Mar 30 at 9:41
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406055%2fhow-to-use-multiple-env-files-like-env-development-with-express-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've tried using dotenv but it seems like you can only use the .env file. Not .env.development and .env.production.
Not true -- see the path
option.
For example, require('dotenv').config( path: `/path/to/.env.$process.env.NODE_ENV` )
For anyone else: i finally went with this:const path = require('path'); require('dotenv').config( path: path.join(__dirname,
../.env.$process.env.NODE_ENV));
– Jonas
Mar 30 at 9:41
add a comment
|
I've tried using dotenv but it seems like you can only use the .env file. Not .env.development and .env.production.
Not true -- see the path
option.
For example, require('dotenv').config( path: `/path/to/.env.$process.env.NODE_ENV` )
For anyone else: i finally went with this:const path = require('path'); require('dotenv').config( path: path.join(__dirname,
../.env.$process.env.NODE_ENV));
– Jonas
Mar 30 at 9:41
add a comment
|
I've tried using dotenv but it seems like you can only use the .env file. Not .env.development and .env.production.
Not true -- see the path
option.
For example, require('dotenv').config( path: `/path/to/.env.$process.env.NODE_ENV` )
I've tried using dotenv but it seems like you can only use the .env file. Not .env.development and .env.production.
Not true -- see the path
option.
For example, require('dotenv').config( path: `/path/to/.env.$process.env.NODE_ENV` )
answered Mar 29 at 23:18
MarlornMarlorn
3312 silver badges14 bronze badges
3312 silver badges14 bronze badges
For anyone else: i finally went with this:const path = require('path'); require('dotenv').config( path: path.join(__dirname,
../.env.$process.env.NODE_ENV));
– Jonas
Mar 30 at 9:41
add a comment
|
For anyone else: i finally went with this:const path = require('path'); require('dotenv').config( path: path.join(__dirname,
../.env.$process.env.NODE_ENV));
– Jonas
Mar 30 at 9:41
For anyone else: i finally went with this:
const path = require('path'); require('dotenv').config( path: path.join(__dirname,
../.env.$process.env.NODE_ENV));
– Jonas
Mar 30 at 9:41
For anyone else: i finally went with this:
const path = require('path'); require('dotenv').config( path: path.join(__dirname,
../.env.$process.env.NODE_ENV));
– Jonas
Mar 30 at 9:41
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406055%2fhow-to-use-multiple-env-files-like-env-development-with-express-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Welcome to Stack Overflow. Why would you need multiple environment files on one host? Normally your development and production environments are on different hosts. (dev on your computer and production in the cloud for example).
– Varcorb
Mar 28 at 20:18
npmjs.com/package/dotenv#should-i-have-multiple-env-files
– lifeisfoo
Mar 28 at 20:24