This was a recruitment task that I went overboard with (as usual 🤦). It uses ExpressJs, NodeJS, Typescript, mongodb and docker-compose to start everything up without any hassle.
Config is stored in .env
file (one to rule them all) and propagated through the containers during build time.
As a code formatter of choice I use xojs configured for my own needs (if you want to use it seamlessly install vscode extension xo).
The app consists of three containers:
- database - straightforward mongodb docker instance
- database seeding - it seeds db with sample data from
database/seed/data/products.json
- backend - it installs all dependencies, builds app from Typescript and serves it on port specified in
.env
file
-
Pull this repository:
git pull https://github.com/Mannhattan/task-coffeemug-api.git
-
Copy
.env.template
contents to new.env
file (and change variables if you need) -
Start production build with docker-compose (database, seeding and backend containers):
docker-compose up --build
(add-d
flag for detached mode)⚠️ if you want to preserve db data then uncommentvolumes
line fromdocker-compose.yml
⚠️ -
start dev environment (needs its own database and changes in
.env
file to accomodate that):npm run dev
-
GET /api/v1/products - gets all products
-
GET /api/v1/products/:id - gets details about specific product
-
POST /api/v1/products/ - creates new product, saves it to database and returns it
-
PUT /api/v1/products/:id - updates existing product and returns it
-
DELETE /api/v1/products/:id - removes existing product from database
- tests
- security
- logging
- all containers are connected in a network and only backend container exposes its port to external use
- typescript lacks proper polish in some places
Hopefully none at this point 😉