How can I read environment variables from the node console? The steps I am doing are the following:
node
> process.env.PORT
> undefined
However, I have defined a PORT variable in a .env file. For context, I am working in an express project with the dotenv package included.
When I import .env vars I put 'require("dotenv").config();' in the root index file(for node). Also note that any vars in the .env file are capitalized. So if our var was COOL_PORT=443 we would access it via process.env.COOL_PORT.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.