Repository navigation
If process.env.NODE_ENV is not explicitly set, it returns undefined instead of development
#7524
|
Hello, I'm using express.js v5.3.0. import express from 'express'
import type { Express, Request, Response } from 'express'
...
const app: Express = express()
const PORT = 8000
app.get('/', (req: Request, res: Response) => {
...
})
...
app.listen(PORT, (): void => {
console.log("hello world")
})
const myenv = app.get('env')
console.log('my env:', myenv) // return `my env : development`
console.log(process.env.NODE_ENV) // return `my env : undefined`
export default appThanks for your help. |
Replies: 2 comments 1 reply
|
Lines 90 to 96 in a419aa7 Express won't override the environmental variable if it is not set, but will set it's own setting using the variable if it is available. |
|
process.env.NODE_ENV is undefined because Node.js never sets it automatically it only reads what your operating system or launch script provides. |
process.env.NODE_ENVreturns theNODE_ENVenvironmental variable and if you don't set it it will returnundefined. This is something managed by Node.js and your OS.app.get('env')returns the app setting called'env', which is set to the value ofprocess.env.NODE_ENVor'development'if that variable does not exist or is empty.express/lib/application.js
Lines 90 to 96 in a419aa7
Express won't override the environmental variable if it is …