Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
"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 Respuestas
Responde la pregunta

0

try

require('dotenv').config()

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda