The code was written by the professionals for educational purposes. Don't repeat at home.
npm install- install packages- Create
.envfile, copy values from.example.env
npm run docker:dev:db- create and start a database in docker containernpm run migrate:latest && npm run seed- apply the migrations. Run only once, next time you start the server - skip this stepnpm run dev- run the server
- Download and install the official Postgres v.12 package for your OS - https://www.postgresql.org/download/
- Using a DB observer tool (PGAdmin, Dbeaver, etc.) create a database
- Update the
.envwith the relevant values:DATABASE_PORT(default during installation is5432)DATABASE_NAME(name of a newly created database)DATABASE_USER(default username during installation ispostgres)DATABASE_ACCESS_KEY(password to thepostgresuser, which was also set during installation)
npm run migrate:latest && npm run seed- apply the migrations. Run only once, next time you start the server - skip this stepnpm run dev- run the server
- Make sure the server is not running (stop the
npm run devprocess) npm run test- tests should be all passing
- Alternatively, to run the tests under the fully containerized environment:
npm run docker:test- bring up the database and server within a docker environment, run the tests, then stop the server container.
Please note, thehw_db_testcontainer will still be running.
- Issue: running the
npm run docker:testcommand fails with:
1 error occurred:
* checking context: can't stat ...
- Solution: run
sudo chown -R $USER .docker_pgdata_test/in terminal, while on the repo top level - Another solution: drop all related existing containers and re-run the command
- Issue: running the
npm run docker:testcommand fails with:
failed to solve: failed to solve with frontend dockerfile.v0: failed to build LLB:
error from sender:
open ./lecture-starter-backend-structure/.docker_pgdata: permission denied
- Solution: apparently, the
docker:dev:dbcommand was invoked before, which conflicts with the previously created container data. Simply delete the pg related foldersudo rm -rf ./docker_pgdata