The script should indicate that

Where business professionals discuss big database and data management.
Post Reply
hasinam2206
Posts: 19
Joined: Sun Dec 22, 2024 3:49 am

The script should indicate that

Post by hasinam2206 »

If you run the same command again with NODE_ENV set to production, you will see that it will remain undefined. JavaScript Copy the code NODE_ENV=production node dotenv-example.js The output should now be: JavaScript Copy the code No value for FOO yet: undefined Now the value for FOO is: undefined If you don't want to modify your code itself, you can also use -rNode's argument to load dotenv when running the script.

To do this, replace your file dotenv-example.jswith: 11-digit phone number format philippines JavaScript Copy the code console.log('The value for FOO is:', process.env.FOO); Then run the file as you normally would: JavaScript Copy the code node dotenv-example.js the current value of FOOis undefined. Now run it with the appropriate flag to call dotenv : JavaScript Copy the code node -r dotenv/config dotenv-example.

Image

js The result is that FOOis now set to barsince the file .envwas loaded. If you want to know more about dotenv, check out its documentation. Load .env files differently There is also another module based on dotenv to make loading environment variables easier. The result is node-env-run or nodenv. This command line tool will load an .

Initialize the values ​​using dotenv, and then run your script. You can install it globally, but this is only recommended for development purposes and at the local project level. Install it by running: JavaScript Copy the code npm install node-env-run --save-dev Then create a file nodenv-example.jsand insert this code into it: JavaScript Copy the code console.
Post Reply