Fast Lazy Bee is a toy RESTful API developed in TypeScript with the Fastify framework for educational purposes.
Two different options are available for running Fast Lazy Bee in your local machine.
N.B.: Regardless of the local run strategy you choose, you must be sure the Docker Engine is running before launching Fast Lazy Bee.
Tool | Version | Required by |
---|---|---|
Docker | (a recent one) | Strat. 1 and Strat. 2 |
Docker Compose1 | (a recent one) | Strat. 1 |
Node.js2 | 21.7.3 | Strat. 2 |
This is the recommended strategy, and it requires Docker and the Docker Compose plugin to be installed on your system. No need for a local MongoDB instance or another Node.js version installed on your machine!
The provided run scripts perform a multi-container setup that will result in two containers for the application (fastLazyBee-app) and the database (fastLazyBee-mongo), respectively.
Give the run script execution permission with chmod +x ./run.sh
, then launch it with
./run.sh
Assuming the script will have successfully completed its execution, it should communicate the URL where to play with the API via SwaggerUI. The link should be http://localhost:3042/docs.
When you're done, eradicate the poor API from this world by simply launching
docker compose down --remove-orphans --volumes
Launch the run script with:
.\run.ps1
From here on, no significant differences compared to GNU/Linux and macOs.
The application is run within a test environment so that no running database container is expected to be there beforehand, nor do you need to directly interact with Docker.
A fresh (dockerized) MongoDB instance is automatically provisioned by Testcontainers, and torn down when the life cycle of the application ends. No changes to the initial state of the database due to server activity are persisted after teardown, nor should you expect container junk to be left around.
Install the project dependencies with npm ci
, then run the command:
NODE_ENV=test npm run dev
You should now be able to access the API and interact with it at http://localhost:3000/docs.
You can stop the application and trigger container teardown at any time by simply pressing Ctrl+C in the terminal window whence you run the script.
Footnotes
-
Be sure the new
docker compose
syntax (no hyphen!) is available. Long story short, you should have the Compose plugin (v2) installed for the Docker CLI, not the original Docker Compose implementation (v1). See replies to this question in Stack Overflow. ↩