'How to get env variables to be recognized when running nodejs CLI globally
I made a simple nodejs CLI using commander to send API requests. I am on Windows. I want to run the CLI from anywhere by calling the app name without having to type node.js. I was able to do this using npm link. I am using dotenv for environment variables where I store the API key. However, it looks like the app only picks up the variables from my .env file when I run the app from within the app folder. I am able to run the app from anywhere, but when I use a CLI command that calls a function that accesses the .env file, I get an undefedined TypeError. It only works if I run this command from within the app folder. Is there a way I can get this to work where I don't need to be in the app folder and can run CLI commands that access the .env file?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
