Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

282
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda