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:
npm install @hansaka02/news-fetcher
usage
To use this module, you can do the following:
Import module
const { getNews } = require('@hansaka02/news-fetcher');
fetching news text
(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
Top Stories(dont input anything)
World
Nation
Business
Technology
Entertainment
Science
Sports
Health
how its use
/*------------you can use catogory or quary to filter news------------*/
getNews({category:'science'})
getNews({query:'sri lanka sports'})