Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!