@hansaka02/news-fetcher
Version:
An advanced Node.js module to fetch the latest news from Google News RSS.
67 lines (51 loc) • 1.26 kB
Markdown
# news Module
An advanced Node.js module to fetch the latest news from Google News RSS.
## Installation
To install the module, run the following command:
```bash
npm install @hansaka02/news-fetcher
```
## usage
To use this module, you can do the following:
### Import module
```javascript
const { getNews } = require('@hansaka02/news-fetcher');
```
### fetching news text
```javascript
(async () => {
try {
console.log('Fetching latest news...\n');
const news = await getNews();
if (news.error) {
console.error('Error fetching news:', news.error);
return;
}
// Display the news in a formatted way
news.forEach((item, index) => {
console.log(`${index + 1}. ${item.title}`);
console.log(` 🔗 ${item.link}\n`);
});
} catch (error) {
console.error('Unexpected error:', error.message);
}
})();
```
### you can input catogories format
```plaintext
Top Stories(dont input anything)
World
Nation
Business
Technology
Entertainment
Science
Sports
Health
```
#### how its use
```javascript
/*------------you can use catogory or quary to filter news------------*/
getNews({category:'science'})
getNews({query:'sri lanka sports'})
```