You need to make sure you have Docker installed. Current instruction is written for the Docker v4.34.
Use npm ci
to install all the dependencies with correct versions.
Project uses different .env
files for each environment: .env.development
,
.env.production
, .env.test
.
Locally you only need .env.development
and .env.test
.
You can create it based on the .env.template
. Just copy .env.template
, rename it and fill missing
variables.
Important. In the .env.test
you will need to use another name for the DB,
since when tests are running, they're automatically filling and cleaning the DB,
so all your data from the DB used for development might be lost.
Run npm run docker:dev
or npm run docker:dev -- -d
to run it "in background".
It will be working in HMR mode, so any changes to the codebase will be reflected.
Now it should be accessible under the port that you defined in the .env.development
file.
- Sometimes when running
npm run docker:dev
it might stuck running migrations due to DB connection issues. It's a very rare case, but if this happens, simply run the command again.
There's a pgAdmin available under the port 8001
. You can modify configuration for email and password of the dashboard in the env file. On the first setup, after logging in on the dashboard you will see "Add new server". Click on it, give it whatever Name you want.
Under the Connection
tab you will need to fill a few fields:
- Host name/address –
db
(postgres service name fromdocker/dev/docker-compose.yml
file) - Username – value from the
APPLICATION_DB_USERNAME
env variable - Password - value from the
APPLICATION_DB_PASSWORD
env variable
npm run docker:dev:down
to stop containers. All the data will still be stored in the DB.npm run docker:dev:destroy
stops containers, and Completely destroys all the images, container and volumes. It means all the data will be erased from the DB. Useful when you want to test new migrations, or DB structure was damaged.- Use
docker:dev:run-in-container -- <some command>
to run any command inside running docker container. For exampledocker:dev:run-in-container -- npm run migrate:dev
to run migrations anddocker:dev:run-in-container -- npm run migrate:dev:undo
to undo them.
For whatever reason if you don't want not to use Docker, you still need to complete first 2 steps described above, and then follow these instructions:
If you can access your user and you know how to create a DB, you can ignore that section.
If you don't know how to access your postgres user or DB:
- Install Postgres.app for all existing postgres version here (it will install all needed Posgres versions).
- Open the app, in the interface click on the "+" on the bottom left and add a new V11 server.
- Click "Initialize" button from the interface.
- If you have error "Post already in use", try to close apps that are using that port, or click on the server V11 in the interface and change port to 5433 (first option is much better)
- Connect to default DB user using either
psql -h localhost -p 5432 -U postgres -d postgres
or just click on the "postgres" db in the Postgres.app. If you changed port on the previos step, update the port
-
Now run following commands to setup a user (update dumb values with your own):
-
You can omit first two steps if you don't mind using your current user.
CREATE USER myuser WITH PASSWORD 'secretpassword';
ALTER ROLE myuser SUPERUSER;
CREATE DATABASE "budget-tracker";
- That's it.
- Install Redis via
brew install redis
- Then
brew services start redis
npm run migrate:dev
If you have an error running this command, you probably need to install Postgres. Read the guide below.
If you encountered any errors during npm run migrate:dev
, you can run
npm run migrate-undo:dev
to undo migrations. If you still facing issues, you
can clear the DB using these two commands:
drop schema public cascade;
create schema public;
They will completely clean the DB and you will be able to run migrations again.
npm run dev
But better use Docker 🙈