The idea behind this project lies in simplicity. It is the template for a generic API with the implementation of user registration and authorization. It's just a sample of how to write a service, feel free to use this project whatever way you need.
The project uses some DDD practices, like Value Objects and Application Services.
The code is written in TypeScript. The API bases on the express library, with the service written in node.js. It uses MongoDB to store data and mocha & chai for testing purposes.
There is an error handling middleware implemented, so you don't have to worry about returning errors from the API. Just throw one and see the result!
Authentication is made with the use of jsonwebtoken library.
Use the package manager yarn to install dependencies.
yarn
You can run it either using the docker-compose up
command:
docker-compose up
And open the url: http://localhost:8080/api/v1
Or you can open the user-service directory, rename .env.example
file to .env
and run one of the following commands:
yarn start
yarn dev
yarn debug
yarn prod
The advantage of the docker-compose is that it sets up the MongoDB database so you don't have to worry about it. And the more services you have, the harder it will be to run them 'by hand'.
To see the API documentation please open http://localhost:8080/api/v1/docs/
If you run the API using docker-compose up
command all the tests are being executed.
But if you need to just run the tests, you can either use docker command:
docker-compose up --build --abort-on-container-exit
Or go directly to the service you want to test and run
yarn test
/src
.../api
.../application
.../common
.../db
.../events
.../exceptions
.../middlewares
.../models
/tests
...
If you want to know more about the structure and usage of this template, please feel free to visit https://medium.com/@mkocik/41c65f84d9c1 and check the article out!
If you like the project enough to collaborate and you see some improvements to be made, please create a Pull Request.