In Module 1, you learned about environment variables for storing configuration like the server PORT. For database connections, environment variables are even more critical because they contain sensitive credentials that must never be hardcoded in your source code.

Setting Up Database Environment Variables

Create a .env file in your project root (same level as package.json) with the following values (they must match what you used in lesson 1):

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=password
DB_NAME=blog
PORT=3000

Important: Add .env to your .gitignore file so it’s not committed to version control.

Tags: