This API is developed in NodeJs, Express and Typescript, using SOLID principles to increase scalability and facilitate the reading of the project code.
Run:
yarn install
The .env file has the project's environment variables.
- REDIS_PORT: port where the redis server is running;
- HATCHWAYS_API_URL: url to fetch data from Hatchway API;
- CACHE_EXPIRE_TIME_IN_SECONDS: time to expire the requests cache, in seconds.
Run:
yarn dev
The server starts at: http://localhost:3333/
Run:
yarn build
Run:
yarn start
The server starts at: http://localhost:3333/
To run the tests:
yarn test
The project has two cache providers, Node-cache and Redis, natively. By default the project is using Node-cache for caching, to change to Redis just change:
const cacheProvider = new NodeCacheProvider()
at file: src/index.ts
to:
const cacheProvider = new RedisCacheProvider()
at file: src/index.ts
However, to use Redis it is necessary to have a Redis server running in your environment on the same port as the REDIS_PORT environment variable.
If you don't have a Redis server in your local environment, the Redis provider's unit tests will fail.
by Gabriel Sá | Software Developer 😄