The general purpose of the API is to keep track of how a batch of beer is being brewed over time. There are some peripheral information pieces such as employees that are working on the system, the tanks that the batches are being brewed in, actions associated with those tanks, and the recipes for a brew.
Both development and production environments require the use of a .env file to get environment variables. This .env file should never be committed, you can rename the example.env file in the project to .env and it will work.
It contains the following environment variables that are all required for local development with Docker.
- PGUSER -- The PostGres username
- PGDATABASE -- The PostGres database name
- PGPASSWORD -- The PostGres database password
- PORT -- The Port that the database connects to
- IS_NOW -- Required to expose all routes
- AUTH_KEY -- Secret key for authorization
For more information on the PG environment variables, check out the official postgres docker container docs
cp example.env .env
will enable the default configuration.npm ci
will install all of the dependencies.- Run
npm run watch-ts
in a different terminal, this will trigger the typescript compiler to watch the source files for changes and re-transpile them. npm run build-images
will rundocker-compose
, build new images, and run the api.npm run dev
will rundocker-compose
, and run the api.
The postman collections at the root of this repo contains documentation for all of the avaiable api endpoints. It contains *.collection.json and *.environment.json that will need to be imported into postman so that authentication is automated for all requests.
Once the application has started the init
(small data set) or init-live
(large data set) endpoint needs to be hit to initialize the test data for the application. Once hit (after success) this can take between 10 seconds to a minute to load all of the data.
Our Postman collections contain these routes, aptly named init
and init-live
.
If you prefer, the following curl commands can be used to hit both endpoints:
curl -X POST http://localhost:3000/init
curl -X POST http://localhost:3000/init-live
NOTE: for the automatic psql instance check the npm
commands section.
To connect to the docker container and interact directly with the database, follow these steps
- Start up the postgreSQL docker container if it is not already running
- Open up a terminal window
docker ps
to get the name of the running DB docker containerdocker exec -it {name of DB container} bash -l
psql -U {PGUSER} -d {database name}
You should now be logged into the psql program on the docker container
A few things to note:
- every line must either start with a
\
or end with a;
- eg.
\dt
shows all database tables - eg.
SELECT * FROM actions;
selects everything from the actions table
- eg.
\q
to quit the psql shellexit
to exit the docker container
- start: Starts the server using vanilla NodeJs.
- build: Runs the typescript compiler on the source code.
- now-dev: used by the
now
cli when runningnow dev
. There is no need to run this manually. - now-build: used by the
now
cli when runningnow dev
. There is no need to run this manually. - test: Runs unit tests with Jest.
- dev: Starts the development docker environment with the most recently built images. NodeJs version must be version 11.
- debug: Used by docker to start the server for local development with a debugging port enabled.
- psql: Opens a terminal and starts psql on the currently running postgres instance on docker.
- lint: Runs the linter on the project to enforce code styling based on our
tslint.json
configuration. - watch-ts: Starts the typescript compiler in watch mode to automatically update the currently running docker api instance with new changes.