This project is a simple task manager application designed to be a learning resource for developers interested in Docker, Node.js, Redis, and PostgreSQL. The application provides a basic REST API for creating, reading, updating, and deleting tasks.
- Docker & Docker Compose: Used to containerize the application and its services, making it easy to set up and run in a consistent environment. Docker isolates the application and its dependencies, while Docker Compose orchestrates the multi-container setup.
- Node.js: The backend of the application is built with Node.js. This provides the REST API for managing tasks.
- PostgreSQL: A powerful, open-source object-relational database system used as the primary data store for the tasks.
- Redis: An in-memory data structure store, used as a cache to improve the performance of reading tasks.
Before you begin, ensure you have the following installed on your system:
-
Clone the repository:
git clone https://github.com/riz007/task-manager.git cd task-manager -
Start the application:
docker-compose up --build
This command will build the Docker images for the Node.js application and start the containers for the application, PostgreSQL, and Redis. The application will be available at
http://localhost:3000.
.
├── docker-compose.yml # Defines the services, networks, and volumes for Docker Compose
├── Dockerfile # Defines the Docker image for the Node.js application
├── LICENSE # Project license
├── package.json # Node.js project metadata and dependencies
├── README.md # This file
└── src
├── db.js # PostgreSQL connection setup
├── redis.js # Redis connection setup
├── server.js # Node.js server setup and API routes
└── taskController.js # Application logic for handling tasks
The application is composed of three services defined in docker-compose.yml:
app: The Node.js application container.db: The PostgreSQL database container.redis: The Redis cache container.
When a request is made to the API:
- The Node.js server in
server.jsreceives the request. - The request is routed to the appropriate function in
taskController.js. - For read requests (
getTasks), the controller first checks if the data is in the Redis cache. If it is, the cached data is returned. If not, the controller queries the PostgreSQL database, stores the result in the cache, and then returns the data. - For write requests (
createTask,updateTask,patchTask,deleteTask), the controller updates the PostgreSQL database and then clears the Redis cache to ensure that subsequent reads will fetch the fresh data.
To run the tests, you can use the following command:
docker-compose exec app yarn testThis will execute the tests inside the running app container.
This project is licensed under the MIT License. See the LICENSE file for details.