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

280
Vistas
Node Server .env file undifined in server.js

The below screenshot shows my file structure in VS code. I have used npm concurrent to run both backend and frontend simultaneously. My problem is env file is not recognized in the server file. Please tell me what is wrong here.

enter image description here

Second picture

enter image description here

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You can specify the path where the .env file is to dotenv package.

Please modify the following line of code to

require("dotenv").config();

like this:

require("dotenv").config({path: "./back-end/.env"});
about 4 years ago · Santiago Trujillo Denunciar

0

write PORT in .env file in backend folder

PORT = <PORT_NUMBER>

For Ex.

PORT = 3000

Install dotenv in backend folder

npm i dotenv

Import dotenv in server.js file

require('dotenv').config()

or set .env path in

require("dotenv").config({path: "./back-end/.env"});

Then Check by:

console.log(process.env);

Run in backend folder

node server.js
about 4 years ago · Santiago Trujillo Denunciar

0

To use DotEnv, first install it using the command: npm i dotenv . Then in your app, require and configure the package like this: require('dotenv'). config()

    require('dotenv').config();

console.log(process.env.MY_ENV_VAR);
about 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