Node.js RESTful API boilerplate using Traefik, Docker, Docker Compose, Fastify, JWT and Mongodb.
- Node.js >= 14
- Docker
- Docker compose
Install packages using docker:
docker run --rm -it \
-v ${PWD}:/usr/src/app \
-w /usr/src/app \
node:16-alpine npm i
Windows users should switch the PWD variable to your current directory. Alternatively, you can run npm install as follows:
docker-compose run --rm api npm install
Or if you have node installed in your system, install using npm:
npm install
-
Rename the .env.example file to .env and fill variables. The Postgres variables are required for Sonarqube. The SENTRY_DSN variable is not obligatory.
-
Edit your hosts file with:
127.0.0.1 fastify.localhost
127.0.0.1 sonarqube.localhost
In the root of project, run:
docker-compose up
Endpoint | HTTP Method | Description |
---|---|---|
/api/v1 |
GET |
Healthcheck |
/api/v1/users/register |
POST |
Adds a new user |
/api/v1/users/auth |
POST |
Authenticate user |
/api/v1/movies |
GET |
List all movies |
/api/v1/movies/:id |
GET |
Get movie |
/api/v1/movies |
POST |
Adds a new movie |
/api/v1/movies/:id |
PATCH |
Update a movie |
/api/v1/movies/:id |
DELETE |
Delete a movie |
Request
curl -i --request GET 'http://fastify.localhost/api/v1'
Response
{
"message": "Fastify API is on fire"
}
I exported Insomnia collection/data
for so you can test all the endpoints.
To access Sonarqube dashboard, simple access in your browser:
http://sonarqube.localhost
Follow the guide to learn more about the settings and how to run Sonar code analysis.
To access Traefik dashboard, simple access in your browser:
http://localhost:8080
Happy coding!