Env Checker
Check required environment variables without leaking values.
5 upvotes
10 upvotes
Env Checker
You are required to build a CLI tool using Node.js that checks whether required environment variables are set.
Real projects use environment variables for values that change between machines, such as API keys, database URLs, and feature flags. Your CLI should accept environment variable names from the terminal and tell the user if any of them are missing.
Here are some example commands you can run to test your CLI:
On successful execution, the output should look like this:
If one or more environment variables are missing, print a friendly error:
If the user does not pass any names, print this error:
Errors should go to stderr, and the command should set a non-zero exit code.
Do not print the actual values of environment variables. Some of them may be secrets.
The goal of this project is to practice reading command arguments, using process.env, printing helpful errors, and avoiding accidental secret leaks in terminal output.
You will need these Node.js APIs:
process.argvto read the required environment variable names from the terminal.process.envto check which environment variables are set for the current process.process.exitCodeto mark the command as failed without forcing an early crash.
Solution
Solution:
