Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
dotenv file is not recognized by server nodejs

this is my first mern stack project ever and i'm trying to push it to github. i am using mongoose so i had to hide the login and pwd of my account i looked it up and found the .env solution. I created a dot env file

#.env file
Port=5000
CONNECTION_URL=mongodb+srv://+++++++++@cluster0.p5v9c.mongodb.net/++++++?retryWrites=true&w=majority

i ran npm i dot env

then i added import statement: import dotenv from 'dotenv';

and the problem seems to occur here, i tried: dotenv.config();, require('dotenv').config();, require ('dotenv/config');.

the code to of my index js if it helps to solve the solution :

const PORT = process.env.PORT|| 5000;

mongoose.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
    .then(() => app.listen(PORT, () => console.log(`Server Running on Port: http://localhost:${PORT}`)))
    .catch((error) => console.log(`${error} did not connect`));
    
mongoose.set('useFindAndModify', false);

can anyone help me solve this up i would really appreciate it thank you ^^

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After installing you do not need to import dotenv. Remove the line:

import dotenv from 'dotenv';

Include dotenv with just:

require('dotenv').config()

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!