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

189
Visualizações
process.env returning undefined

I've imported dotenv using require('dotenv').config(); at the top of the server.js file. The .env file is in root folder

require('dotenv').config();
//import dotenv from 'dotenv';
// import express from 'express';
// import viewEngine from '../config/viewEngine';
// import initWebRoute from './routes/web';
// import bodyParser from 'body-parser';
var express = require("express");
var viewEngine = require("./config/viewEngine");
var initWebRoute = require("./routes/web");
var bodyParser = require("body-parser");

let app = express();

// config view engine
viewEngine(app);

//use body-parser to post data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// init all web routes
initWebRoute(app);

let port = process.env.PORT;

app.listen(port, ()=>{
   console.log(`App is running at the port ${port}`) ;
});

process.env returns 'undefined'. how can i fix this or is there an alternate way for importing environment file values

PORT=8080
MY_VERIFY_FB_TOKEN=Randomstring
FB_PAGE_TOKEN=pagetoken

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Used your snippets and it's working fine. Try running npm i dotenv again to make sure you have the module installed and updated.

btw, body-parser is deprecated. You can use app.use(express.json()); instead.

about 4 years ago · Juan Pablo Isaza Relatório

0

FIXED the issue. It lacked a .env.example file .env.example works as a guide for creating a .env file with the needed informations that is needs to have the application running.

about 4 years ago · Juan Pablo Isaza 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