Menu

Post image 1
Post image 2
1 / 2
0

Environment Variables in Node.js — What They Are, How dotenv Works, and Why Getting This Wrong Can Ruin You

DEV Community: node·Chinwuba·2 days ago
#oruGablC
Reading 0:00
15s threshold

If you've been hardcoding API keys in your JavaScript files, you're one public GitHub push away from a bad day. I'm Jeffrey — I run a web design agency called Velto and I'm currently 16 weeks deep into learning Express.js properly, starting from the JavaScript foundations most tutorials skip. The problem environment variables solve When your app runs, it needs configuration: what port to listen on, what database to connect to, what API keys to use. The naive approach is hardcoding these values directly in your code: js const PAYSTACK_KEY = " sk_live_xxxxxxxxxxx " ; const DB_URL = " postgresql://jeffrey:password@localhost:5432/velto " ; Enter fullscreen mode Exit fullscreen mode This creates two immediate problems. First, security. If this code ever touches a version control system — especially a public one — those secrets are exposed. GitHub has bots scraping repos for leaked credentials around the clock. This is not paranoia. It happens. Second, portability.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More