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

217
Views
"TypeError: Cannot read property 'toString' of undefined" while connecting to mongodb using env variables

I am fairly new to full-stack, I started learning and making a demo site using node, express, and MongoDB. I was learning through youtube(WebDevSimplified).

i connected my project to my MongoDB using the uri. and was working fine. in the tutorial a new methord was said is: 1.install tool dotenv( npm i --save-dev dotenv ). 2.create a .env file and lode a field-( DATABASE_URL= mongodb://localhost/db ) 3.check if the file is in production env.----

if(process.env.NODE_ENV !== 'production') {
    require('dotenv').parse()
}

4.for connecting to db use uri as.----

mongoose.connect( process.env.DATABASE_URL, {useNewUrlParser: true})

I am getting an error:

TypeError: Cannot read property 'toString' of undefined
at Object.parse (F:\MVC project\webdevSimplified\node_modules\dotenv\lib\main.js:42:7)
at Object.<anonymous> (F:\MVC project\webdevSimplified\server.js:2:23)

the next step is deploying in Heroku. for that I think I require to get this so please help me...

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

try

require('dotenv').config()

over 4 years ago · Santiago Trujillo 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!