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

164
Views
Can someone explain me why .env variables are undefined when I print them?

I've done a Node JS server with ES6 using import and export, but when I want to access to an enviroment variables to print that, they return me "undefined". This is my code :

import express from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import 'babel-polyfill'
import userRoutes from './routes/user.routes.js'
import db from './db/database.js'
import dotenv from 'dotenv'

dotenv.config()

const PORT = process.env.PORT || 5001
const app = express()
db.connection()

app.use(bodyParser.json({ limit: '30mb', extended: true }))
app.use(bodyParser.urlencoded({ limit: '30mb', extended: true }))
app.use(cors())

app.use(userRoutes)

app.get('/', (req, res) => {
  res.send('Hello world')
})
app.listen(PORT, () => {console.log(`Server on port ${process.env.PORT} and secret key ${process.env.JWT_KEY}`)})
about 4 years ago · Juan Pablo Isaza
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!