This is a simple REST API built as coding challenge made for TrueNorth.
See the requirement's list.
CircleCI status:
Coverage
- Node.js
- TypeScript
- MongoDB and Mongo Atlas as Database
- Redis and Redis Labs as Cache layer
- Jest
- AWS lambda
- Eslint
- Docker
- serverless and serverless-offline
You need to install the project first:
npm install
Before running the API, you must have Mongo and Redis installed first.
You can manually install them, or, you can use docker to install it by running:
npm run docker:compose:daemon
You probably want to run the current test suite implementation:
npm test:dev
It is recommended to set the NODE_ENV env var value to 'dev'
export NODE_ENV=dev
Add some users and operations to the database:
npm run data:seed:dev
An then you can start the dev environment by running:
npm run local:start:dev
You can do login as admin user through the API by using curl:
curl -X POST http://localhost:3000/dev/users/login -H "Content-Type: application/json" -d '{"username": "[email protected]", "password": "123456"}'
npm run docker:compose:daemon
Stop Docker environment
npm run docker:stop
Restart Docker environment
npm run docker:restart
npm run docker:clean
Clean Docker environment
npm run docker:clean
When running on CI, the API connects to Mongo Atlas and Redis Labs.
Please make sure you have the proper accounts.
You can create for free, both accounts at https://redis.com/try-free/ and https://www.mongodb.com/cloud/atlas/register .
Setup the following env vars on CI platform:
NODE_ENV="ci"
CODECOV_TOKEN="xxxxxxx" # for codecov service
TOKEN_KEY="mysecret" # for jwt token
REDIS_HOST_LABS="redis-16050.c10.us-east-1-2.ec2.cloud.redislabs.com"
REDIS_PASSWORD_LABS="........"
REDIS_PORT_LABS=16050
MONGO_ATLAS_URL="mongodb+srv://username:[email protected]/?retryWrites=true&w=majority"
MONGO_DATABASE="arithmetic_calculator_api"
Run the default npm test command
to run the test suite for CI.
npm test
By default the application will assume the following stage names and config files:
- test
- prod
- stg
Each one of those will required a related config file:
- ./config/.env.test
- ./config/.env.prod
- ./config/.env.stg
Use the following template:
TOKEN_KEY=mysecret
REDIS_HOST_LABS="redis-16050.c10.us-east-1-2.ec2.cloud.redislabs.com"
REDIS_PASSWORD_LABS="password"
REDIS_PORT_LABS=16050
MONGO_ATLAS_URL="mongodb+srv://username:[email protected]/?retryWrites=true&w=majority"
MONGO_DATABASE="arithmetic_calculator_api"
$ npm run deploy
# or
$ serverless deploy
send an HTTP request directly to the endpoint using a tool like curl
curl https://je6x0x8fa6.execute-api.us-east-2.amazonaws.com/test/users
By default, AWS Lambda limits the total concurrent executions across all functions within a given region to 1000. The default limit is a safety limit that protects you from costs due to potential runaway or recursive functions during initial development and testing. To increase this limit above the default, follow the steps in To request a limit increase for concurrent executions.
- Improve code coverage
- Implement test suite for unit testing.
- Implement test suite for e2e testing.
- Adopt the Data Repository Pattern.
- 100% Ensure the SOLID principles.
- Implement API documentation - swagger OAS.
- APM with datadog - custom error classes in 2 levels: service and controller