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?
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.