Environment Variables in Node.js

preview_player
Показать описание


----
Watch me live:

----
Video Suggestions:

----
Follow Me Online Here:

----
#benawad

----
#benawad
Рекомендации по теме
Комментарии
Автор

Even better! Add/edit this to package.Json
"start": "node -r dotenv/config app.js"

This requires the .env file on npm start.

Obviously app.js is your main JS entry point. Node can also be nodemon if your using it too.

You can remove all call to dotenv from your app.js completely

jeromehurley
Автор

Hi to prevent lint from showing this as a "imports before" issue add this line to top of file:
/* eslint-disable import/first */



problem problem

jeromehurley
Автор

how are you using es6 modules in node?
are you compiling with babel?

gno
Автор

and how do you set variables for dev different from those in prod mode ?

fahemzoldyck
Автор

is there a way to pull .env variables from environemnt.ts file in ANGULAR ?. I'd like something like it:
.env:
IP = localhost
PORT=8000


environemnt.ts:
export const environment = {
production: false,
defaultCompany: "xxx",
basepath: IP;//esta IP seria la del archivo .env
};

camn-bvvq
Автор

Hi Ben, Firstly thanks for your video's. Just love them. So was working on the dotenv file on a project with graphql, sequelize. Now having the dotenv.config() in the index was not working as for the DB connections the env variables were not set. The models index file establishing the sequelize connection runs first and at that point dotenv.config() has not run. So i created a separate folder config/confi.js file only for the DB connection and included the dotenv() config just before that. Just wanted to know your thoughts. Forgot to mention I am talking about dotenv on server. Keep up the Great Work!! Cheers!

nagarajay
Автор

how to switch between development and production environment

murtazahaji
Автор

Hey, love your videos, hate your mic :)

nickwoodward