Home > Net >  I can't access my .env variables!! nodeJS
I can't access my .env variables!! nodeJS

Time:10-07

Server is running on PORT: undefined in undefined mode. MongoDB database connected with HOST: localhost


used to get Server is running on PORT: 4000 in development mode. and suddenly it's undefined for both and every variable in my .env, like cloudinary .. stripe ...

CodePudding user response:

One of the first things you should pay attention to is the file path. Check where your .env file is located in the project. If it is in the root of the project, there is no need to do anything. Otherwise, you must specify the path to the .env file.

CodePudding user response:

You can add this snippet before starting mongoDB to see what's getting to your node process env variables:

console.log(process.env)

Also note that you can pass inline environment variables to node process like this:

PORT=4000 node ./my-script.js

To automatically load .env files, you might be using this package: https://github.com/motdotla/dotenv so be sure that you have all packages installed (npm install or yarn install, depending on what you are using).

  • Related