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 installBefore 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:daemonYou 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=devAdd some users and operations to the database:
npm run data:seed:devAn then you can start the dev environment by running:
npm run local:start:devYou 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": "admin@admin.com", "password": "123456"}' npm run docker:compose:daemonStop Docker environment
npm run docker:stopRestart Docker environment
npm run docker:restart
npm run docker:cleanClean Docker environment
npm run docker:cleanWhen 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:password@cluster0.mie7dav.mongodb.net/?retryWrites=true&w=majority"
MONGO_DATABASE="arithmetic_calculator_api"Run the default npm test command to run the test suite for CI.
npm testBy 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:password@cluster0.mie7dav.mongodb.net/?retryWrites=true&w=majority"
MONGO_DATABASE="arithmetic_calculator_api"$ npm run deploy
# or
$ serverless deploysend an HTTP request directly to the endpoint using a tool like curl
curl https://je6x0x8fa6.execute-api.us-east-2.amazonaws.com/test/usersBy 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