This API is written in Node.js using express.
- Start all required docker containers
npm run start
- On first startup, apply database migrations
bash migrate.sh
- Shutdown using
npm run down
Docker only (requires installation of Docker):
- Start all required docker containers
docker compose --env-file ./dev.env build
docker compose --env-file ./dev.env up -d
- On first startup, apply database migrations
bash migrate.sh
- Shutdown using
docker compose --env-file ./dev.env down
npm run dev
Requires a Postgres instance on port 5432
The API Documentation can be hosted to localhost:8080
by running
npm run apiDoc
If still online, the doc can also be viewed here
api
└─── /migrations
│ │ <timestamp>_migration.js # Migration step definition, create new using 'npm run migrate create <name>'
│
└─── /src
│ app.ts # Application entry point
└─── /api # API routes
│ ...
└─── /service # Service layer contains business logic
│ ...
└─── /data # Data access layer
│ ...
└─── /swagger
│ swagger.yml # API definition in openAPI spec
│ .dockerignore
│ .env # Production environment variables
│ dev.env # Development environment variables
│ .eslintrc.json
│ docker-compose.yml
│ Dockerfile
│ package-lock.json
│ package.json
│ tsconfig.json
│ README.md
| migrage.sh # Script for applying database migrations
Event though Javascript/Typescript supports try
/catch
style error handling, it is not widely used in this project. Instead, functional style error handling using the Either
monad is used where applicable.
By doing this, it is always clear which function threw an error without wrapping each individual statement in a try
/catch
block. Furthermore, by explicitly returning errors from functions, they are represented in the type system.
Typescript does not enforce handling of throwing
functions, so it is very easy to miss a try
/catch block
.
However, try
/catch
might still be used with Promise
s, though the .then
and .catch
methods are prefered.