I am using dotenv
module to load environment variables from .env
file.
.env
:
# config DAILY_REPORT_SCHEDULE='*/1 * * * *' PORT=8080 NODE_ENV=development DOTENV_DEBUG=true # credentials PROJECT_ID=shadowsocks-218808 KEY_FILE_NAME='/Users/ldu020/workspace/nodejs-gcp/.gcp/shadowsocks-218808-7f8e109f4089.json'
As you can see, I add two comments within .env
file.
dotenv.js
:
require('dotenv').config({ debug: process.env.DOTENV_DEBUG === 'true' });
dotenv
give me debug messages:
[dotenv][DEBUG] did not match key and value when parsing line 1: # config [dotenv][DEBUG] did not match key and value when parsing line 6: [dotenv][DEBUG] did not match key and value when parsing line 7: # credentials [dotenv][DEBUG] did not match key and value when parsing line 10: [dotenv][DEBUG] did not match key and value when parsing line 11:
I know the reason why got these debug messages is I added two comments and some new line within .env
file. dotenv
does not parse .env
file correctly.
How can I solve this?
As you said, the only way to comment is at line level with the # character. A workaround would be looking for a shortcut in your IDE to employ multi-line editing (e.g. use Shift + Alt + Arrow Keys on Visual Studio Code in Linux).
The . env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can customize your environment variables as desired by modifying your . env file.
env file should be particular to the environment and not checked into version control. This. env. example file documents the application's necessary variables and can be committed to version control.
It is possible as of mid-2019.
Start the line with #
symbol. See the docs:
lines beginning with # are treated as comments.
For vlucas/phpdotenv the same situation.
The inline comments are not supported for sure for motdotla/dotenv
.
The problem is the different line break.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With