This project is created as an assignment for the position of Backend Intern at Medbikri. It is a Node.js and Express.js application which uses the Youtube Data API V3 to periodically fetch the latest videos related to a pre-defined topic and save them to the MongoDB Atlas Database. This application also provides the API to fetch the stored video data in a paginated response sorted in descending order of published datetime. The users can also use the search API to search the stored videos using their title and description.
- Inside the project directory, run the following commands in the terminal:
npm i
- Now, go to the Google Cloud Console > select
APIs and Services
from thenavigation menu
> Then click on theENABLE API AND SERVICES
button > Search for "YouTube Data API v3" > Enable the API.
Alternatively, you can also visit this link: https://console.cloud.google.com/apis/library/youtube.googleapis.com. - After enabling the YouTube API, generate new Credentials (API key) for this YouTube Data API.
- NOTE: A comma separated list of API keys is necessary to utilize the feature of multiple API keys
- Create a MongoDB Atlas cluster
- In the
Database
tab underDeployment
section, click on theConnect
button. - Choose Connect your application
- Under the
Add your connection string into your application code
section, uncheck the Include full driver code example - The string being displayed now, is the connection string for your cluster. Use this string in the next steps.
Now create a new .env
file in the project's root directory similar to the provided example.env
file and store the required comma separated list of Google API Keys and the atlas connection string in the required variables.
After that, if you have nodemon installed, then simply run the following command:
nodemon server
Create a GET request to the following url:
http://localhost:3000
with the following query parameters:
page
- to specify the pagelimit
- to specify the number of results to fetch from that page- Both the values should be greater than 1
Create a POST request to the following url:
http://localhost:3000/search
with the following body in JSON format:
{
"title":<string-to-search>,
"description":<string-to-search>,
}
NOTE: Both title and description are optional