HTTP Based API that sends emails through different providers to prevent downtime.
- NodeJS 12
- Typescript
- ExpressJS
I chose this stack because it works well for this type of microservices and I'm also familiar with it. I like how the language (Javascript/Typescript) and platform (NodeJS) evolved over the past few years. There are also mature libraries / frameworks by now and the community keeps growing. It also has better developer experience compared to technologies like Java.
ExpressJS is the most popular micro framework for NodeJS, but I could also have used Koa or something more oriented to building APIs like Hapi.
Typescript is a big improvement to the stack because it adds robustness and mantainability to the application. It may be harder to setup but it improves the dx: makes the code easier to read, write (better autocomplete) and refactor, besides adding documentation.
Check technical / architectural decisions document for more details
- Install dependencies
npm i
- This project uses dotenv so you'll need to create an
.env
file with the configurtion. Use.env.example
as reference.
Note: provider number defines priority
- Start the server in dev mode
npm run dev
Using docker
and docker-compose
you can easily recreate the environment:
- NodeJS server
- Swagger UI
- PostgreSQL
- Open
docker-compose.yml
and edit the env variables accordingly.
Note: provider number defines priority
- Install dependencies and build the app
npm i
npm run build
- Start the application
docker-compose up
The application is exposed on port http://localhost:3000 by default and swagger ui on http://localhost:9999
The tests are implemented in jest. To run them:
npm test
Code style is enforced with prettier
and linting is done by tslint
. To run it manually:
npm run lint
OpenAPI was used to document the API. It is exposed on http://localhost:3000/api-docs to be consumed by swagger-ui
Two endpoints are exposed as reference:
/status/health
- to check availability/status/config
- to expose the config