I am learning environment variable in Nodejs. I followed a tutorial video and wrote the exact same code in VS Code to set PORT value in the terminal. But for some reason, the output of PORT is undefined.
In editor, my code is like
//This is index.js file
const port = process.env.PORT;
app.listen(port, () => {
console.log(`listening to port ${port}...`)
})
In terminal, I typed set PORT=2000
and pressed Enter.
In the next line of terminal, I typed node index.js
.
The output in the terminal is listening to port undefined
.
My OS is Windows. I tried solutions online, such as PORT=2000 node index.js
and SET PORT=2000 node index.js
. But none of them worked.