2

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 ...

2
  • Can you please add some more descriptions to your problem, like some code what you are using? Commented Oct 6, 2022 at 18:38
  • I'll just shamelessly promote wj-config as a replacement for your configuration needs. Commented Oct 7, 2022 at 3:57

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

it works !! but only with npm start /// with nodemon I still get undefined for the env variables. (logged them to the console and I got undefined) I think the trouble with nodemon here
3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.