With the appropriate flag to call

Description of your first forum.
Post Reply
hasinam2206
Posts: 18
Joined: Sun Dec 22, 2024 4:30 am

With the appropriate flag to call

Post by hasinam2206 »

Log('no value for foo yet:', process.env.foo); if (process.env.node_env !== 'production') { require('dotenv').config(); } console.log('now the value for foo is:', process.env.foo); next, create a file named .env in the same directory, with the following contents: javascript copy the code foo=bar run the script: bash copy the code node dotenv-example.js the output should look like: bash copy the code no value for foo yet: undefined now the value for foo is: bar as you can see, the value was loaded and set using dotenv.

If you run the same command again with node_env 11-digit phone number format philippines set to production, you will see that it will remain undefined. Bash copy the code node_env=production node dotenv-example.js the output should now be: bash 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 -r node's argument to load dotenv when running the script.

Image

Edit your file dotenv-example.js : javascript copy the code console.log('the value for foo is:', process.env.foo); then first run the file normally: bash copy the code node dotenv-example.js the script should report that the current value for foo is undefined. Now run it dotenv: bash copy the code node -r dotenv/config dotenv-example.
Post Reply