For this project, I have created a backend REST API using Node.js with Express and MongoDB as the database. The API will allow users to search for posts based on a provided keyword. The external API used for this example is https://jsonplaceholder.typicode.com/posts.
Want to check online? 🚀Live Link 📕Postman Documentation
- Node.js
- Express.js
- MongoDB (Mongoose for ODM)
- TypeScript
This project aims to create a backend REST API that enables users to search for posts based on a keyword. The API interacts with an external API to retrieve posts and matches the keyword in the title and body. Matching posts are stored in a database along with user search actions, creating a one-to-many relationship between searches and matching posts. The API also logs user IP addresses and timestamps for each request.
To install the project please follow the following steps.
git clone https://github.com/MHNahib/search-api.git
cd search-api
npm iRecommended node version: v18.17.1
Clone the project
git clone https://github.com/MHNahib/search-api.gitGo to the project directory
cd search-apiInstall dependencies
npm iStart the server
npm run devTo run this project, you will need to add the following environment variables to your .env file
DB_URI=YOUR_DB_URI
EXTERNAL_API=https://jsonplaceholder.typicode.com/posts
GET / GET /search GET /search?keyword=<keyword>| Query | Type | Description |
|---|---|---|
keyword |
string |
Any keyword to fetch. |
To deploy this project run
npm run build