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

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

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 Denunciar

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 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