ConfigModule Basics — Series 3

Preview — 3 of 10 questions

What does config.get('PORT') return?

javascript
PORT = 3000
GREETING="hello world"   # a comment
EMPTY=
A'3000' as a string — but the spacing around = is a common source of trouble, since some parsers keep the surrounding whitespace in the key or the value; keeping KEY=value with no spaces avoids the question entirely
B3000 as a number, since the value is numeric
Cundefined, because whitespace around = makes the line invalid
D' 3000', with the leading space always preserved

Why does this usually fail?

javascript
PRIVATE_KEY=-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBg...
-----END PRIVATE KEY-----
APrivate keys may not be stored in environment variables at all
BThe value exceeds the maximum length of an environment variable
CEach line is parsed independently, so only the first line becomes the value and the rest are treated as malformed entries — a multi-line value needs quoting with escaped newlines ("-----BEGIN...\n...") or, better, base64 encoding, which sidesteps the whole question
DKey material is rejected because it contains dashes

What does this achieve, and what is the caveat?

javascript
ConfigModule.forRoot({ envFilePath: `.env.${process.env.NODE_ENV ?? 'development'}` });
AIt merges every .env.* file in the directory
BIt requires the named file to exist, failing startup otherwise
CIt changes only which file is written when configuration is saved
DIt selects the file to load per environment — .env.test under tests, .env.development locally — with the caveat that NODE_ENV must already be set when the module's metadata is evaluated, and that a missing file is silently ignored rather than reported

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.