47
loading...
This website collects cookies to deliver better user experience
process.env
object.$HOME
variable provided by the OS, which points to the home directory of the user. Any application has access to this variable and, can use it for different purposes. In Node.js applications .env variables are used for credentials, which should not be hard coded or change based on the environment. Other use cases are for example:process.env
to make them available. To read an environment variable:// hello.js
const name = process.env.NAME;
console.log(`Hello, ${name}!`);
hello.js
and set the NAME environment variable for the process:NAME="Mario" node hello.js
Hello, Mario!
.export NAME='Mario'
export DEBUG=true
node ./hello.js
Hello, Mario!
..env
file in the root directory of your app, which contains key/value pairs defining the environment variables. The module dotenv reads this file and appends it to process.env
, which makes it available for the application.