Setting Up Your .env
File for Local Development 🛠️
To set up your local development environment, you'll need to create and configure a .env
file at the root of your project. This file will store environment variables necessary for your backend application and local PostgreSQL setup.
This .env
file will be used with docker-compose
to manage your local development environment.
⚠️ This .env
file is for local development only, not for staging or production.
1. Create the .env
File 📂
- Navigate to the root directory of your project.
- Locate the file named
.env.example
. - Copy and rename it to
.env
.
Your .env
file should now look like this with default values:
Environment Configuration 🌍
NODE_ENV=development
: This sets the environment to development mode.
Server Configuration 🖥️
PORT=4000
: This defines the port number on which your backend server will run.
PostgreSQL Database Configuration 🗄️
These variables will be used by docker-compose
to configure your local PostgreSQL instance:
-
DB_NAME=launchgoatDev
: Name of the local development database. -
DB_USERNAME=launchgoatDevAdmin
: Username to connect to the PostgreSQL database. -
DB_PASSWORD=hello
: Password for the PostgreSQL user. -
DB_SERVICE_NAME=postgres-db
: Service name for the database, as defined in yourdocker-compose.yml
. -
DB_PORT=5432
: Port number for your local PostgreSQL service.
⚠️ You can change the default values if needed, but for practice, I recommend sticking with the default settings.
2. Why Use This .env
File? 💡
This .env
configuration allows you to manage environment-specific variables for your local development environment. By using docker-compose, the database service is containerized, making it easier to manage and avoiding conflicts with other services.