This is a sample Node.js application that integrates MongoDB for data storage and Redis for caching. The application showcases basic CRUD operations and serves as a starting point for building more complex applications.
Before running the Node.js application, ensure that you have the following installed:
- Node.js
- MongoDB
- Redis
-
Clone the Repository:
git clone https://github.com/ribhar/redis_with_node.git -
Navigate to the Project Directory:
cd redis_with_node/ -
Install dependencies using npm.
npm install -
Run Redis server on your local machine.
redis-server -
Start the Node.js server.
npm start
Ensure that you configure the environment variables for the application. You can use the provide .env or Create a new .env file in the root directory and modify the variables as needed. Below is an example of the .env file:
PORT=8080
MONGO_URI=your_mongodb_uri
REDIS_HOST=your_redis_host
REDIS_PORT=your_redis_port
Replace your_mongodb_uri with your MongoDB connection string, and your_redis_host and your_redis_port with the appropriate Redis connection details.
You can access the application at http://localhost:8080. The API endpoints will be available for performing CRUD operations on the data.
To compare the response time of the two API calls, follow these steps:
-
Make the first API call to
http://localhost:8080/api/users/:idwith the provided sample request body. -
Note the time taken to receive the response.
-
Make the second API call to the same endpoint.
-
Compare the response times of both API calls.
The folder structure for the application is as follows:
- src
- config
- config.ts
- db.config.ts
- redis.config.ts
- controllers
- user.controller.ts
- models
- user.model.ts
- routes
- user.routes.ts
- app.ts
- package.json
- .env
- .gitignore
- tsconfig.json
- README.md
Feel free to contribute to the project by creating pull requests or reporting issues.
This project is licensed under the MIT License - see the LICENSE file for details.
This application was created as part of a coding assessment and serves as a basic implementation of a Node.js server with MongoDB and Redis integration. Special thanks to the creators of Node.js, MongoDB, and Redis for their excellent tools and documentation.