To install MongoDB we need to execute a series of steps
We need to install MongoDB on our PC, we can do this in the following link:
We are going to create in our local disk C: a folder called data and inside it a folder called db, it would look like this: C:\data\db
We have to add the file bin to the path of our environment variables, normally this is located in C:\Program Files\MongoDB\Server\6.0\bin
Finally we start our MongoDB service, in our terminal we execute the following command
$ mongod
We can use Compass to see our DB when it is created or some other IDE that can connect to a Mongo DB like Navicat or another
We clone the project, and get our node_modules
$ npm install
We run the API with the NestJS command
$ nest start
Or we can execute the following command to see the changes in the API automatically
$ nest start:dev
The API has a CRON (Task scheduling) and when the application is started it runs every hour, what it does is get the news from the provided URL and insert the information in the DB.
We can modify the time so that it runs every 10 seconds or every 10 minutes and thus be able to see the functionality and have records in the DB.
In our node-new.service we can change the CRON time from EVERY_HOUR to EVERY_10_MINUTES or EVERY_10_SECONDS or even some specific time.
I have generated a swagger to make it easier to request and consume the API.
This can be found in the following link:
I have also generated a collection in Postman which you can import and use in your client. The routes and request are ready to be used
Link a importar: https://www.getpostman.com/collections/e145d5f7e3c7683675c6
In the endpoint that obtains the information from the database, it has filters (node-news/hits/filters) such as:
Pagination: here it shows the news 5 by 5 and the default page is 1.
Filter by Author: for this filter the author field is used where it shows us the author's news that we place in the request.
Filter by title: in this filter we use the storytitle field since the title field returns null in all news.
Filter by tags: In this filter we use the tags field to filter the API response.
Please use exact words to use the filters, for example:
I have one or several elements with the title "Node News in this year", if I want to use the title filter, I have to search for any word that is equal to any of the title but the same as it is written in the registry
Not this way ❌ Filter title: node news or ❌ Filter title: news this Year
Correct way ✅ Filter title: Node News or ✅ Filter title: News this year
For the configuration of the Linter I use the TypeScript and Prettier rules, you can see it in the file .eslintrc.js.