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;








1















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?










share|improve this question



















  • 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















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?










share|improve this question



















  • 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








1


1






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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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












  • 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












1 Answer
1






active

oldest

votes


















1

















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` )






share|improve this answer

























  • 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














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
);



);














draft saved

draft discarded
















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









1

















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` )






share|improve this answer

























  • 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
















1

















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` )






share|improve this answer

























  • 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














1














1










1










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` )






share|improve this answer














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` )







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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





















draft saved

draft discarded















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현