A basic Node.js RESTful API for managing tasks and getting metrics. API Documentation can be found here
- Node.js
- Express.js
- PostgreSQL
- Prisma ORM
- Docker
- Jest
- Code written in JavaScript ES6+
- Containerized application using Docker
- Request validation using Joi for 400 Bad Requests
- HTTP request logging using Morgan middleware
- Gzip compression of response body using Compression middleware
- Automatic code linting with pre-commit hook using ESLint + Husky for better code quality
- ≈100% code coverage using Jest integration tests
- Handled errors and edge cases using a custom error handler middleware
- API Documentation with Postman
- Node Version Manager (instructions)
- Node v18.18.0
$ nvm install 18.18.0 $ nvm use 18.18.0
- Docker CLI / Docker Desktop (instructions)
- Docker Compose (included in Docker Desktop; instructions)
-
Clone this repo:
git clone https://github.com/jebinphilipose/task-api.git
-
Change working directory:
cd task-api
-
Setup environment variables:
cp .env.sample .env.development.local && cp .env.sample .env.test.local
And modify
.env.development.local
and.env.test.local
to have appropriate values.NOTE: You must enter different values of
db
,user
,port
andpassword
fordevelopment
andtest
environments. -
Setup and run
development
server:npm run docker:dev:up
Alternatively, if you don't have Node installed on your local machine, run:
docker-compose -f docker-compose.dev.yml --env-file .env.development.local up -d
-
Verify if server is running:
curl 'http://localhost:3000/api/v1/ready'
-
To view logs:
$ docker ps # copy container id of 'task-api-dev-server' image $ docker logs --follow <container-id>
-
To stop the container after you're done:
npm run docker:dev:down
Alternatively, if you don't have Node installed on your local machine, run:
docker-compose -f docker-compose.dev.yml --env-file .env.development.local down
- Setup and run
test
server:Alternatively, if you don't have Node installed on your local machine, run:npm run docker:test:run
docker-compose -f docker-compose.test.yml --env-file .env.test.local run --rm server
- To stop the container after you're done:
Alternatively, if you don't have Node installed on your local machine, run:
npm run docker:test:down
docker-compose -f docker-compose.test.yml --env-file .env.test.local down
- Project is structured using MVC architectural pattern
- Common functionalities have been moved out to separate modules which enhances readability, mantainability and reusability of code
- Error handling is done properly using a custom middleware
- All edge-cases have been thought (like not allowing user to send a negative page query param in GET /tasks API) and 400 is sent while making a bad request
- Validations are performed both on request-level (using Joi) and DB-level (using Prisma ORM)
- REST API best practices have been considered like using proper HTTP verbs (GET, POST, PUT) and status codes (200, 201, 400, 404, 500)
- Code quality is maintained using JavaScript ES6+ features (async/await, arrow functions, higher order function like map and reduce, etc), linting (ESLint + Husky), and ≈100% code coverage (with Jest integration tests)
To know more about the endpoints and how to make requests, check the API documentation here
This project is licensed under the MIT License - see the LICENSE file for details