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

Viewed 89

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}`)})
0 Answers
Related