Friday 21 February 2020

Display RSS feed on Vue.js Frontend

I want to display a series of articles from a Google Alerts feed. I got it working in Javascript. How do I convert my frontend as a Vue.js component and display it on my Vue.js application?Here is the code:Client: Test page

Latest articles

Backend:const feedparser = require('feedparser-promised'); const express = require('express'); const app = express(); const server = require('http').Server(app); const io = require('socket.io')(server); const fs = require('fs'); server.listen(8000); console.log('Server started on localhost:8000'); let url = 'https://www.google.ie/alerts/feeds/10663948362751557705/4511034072220974544'; // Declare a variable for the feed content let feed = []; // Parse the feed feedparser.parse(url).then(items => { // Update the variable with the new data for (const [i, item] of items.entries()) { // Retrieve the ten first elements, with their title and description // And add them to the feed array if (i < 9) { feed.push({ title: item.title, link: item.link }); } } // Write it to a file so you can know how to parse it better // The callback is mandatory, but it's useless here fs.writeFile('feed.json', JSON.stringify(items, null, 2), 'utf-8', (data) => {}); }); // Define the default route app.get('/', (req, res) => { // Render the page res.render('test.ejs'); // Send the data to the client using socket.io io.on('connection', io => { io.emit('feed', { feed: feed }); }); });

Submitted February 21, 2020 at 06:09PM by RyboXBL

No comments:

Post a Comment