Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of using feedparser (https://github.com/danmactough/node-feedparser) with ES6 on node.js >= 4.0.0
'use strict'
const FeedParser = require('feedparser')
const request = require('request')
let req = request('https://github.com/danmactough.atom')
let parser = new FeedParser()
req.on('error', (err) => {
// handle request error
console.log(err)
})
req.on('response', (res) => {
// check if status code is not correct
if (res.statusCode !== 200) {
return req.emit('error', new Error('Bad status code'))
}
// if the res is correct, when can pipe the response
req.pipe(parser) // pipe response to feedparser
})
parser.on('error', (err) => {
// handle parser error
console.log(err)
})
parser.on('end', () => {
// handle that we've finished reading articles
console.log('End parsing')
})
parser.on('readable', () => {
let item = parser.read()
let meta = parser.meta // get the metadata of the feed
while (item) {
// do whatever you want with the item
console.log(item)
// get the next item, if none, then item will be null next time
item = parser.read()
}
})
@midudev

This comment has been minimized.

Copy link
Owner Author

@midudev midudev commented Jan 25, 2016

Used Standard Style to code the gist: https://github.com/feross/standard

@marti1125

This comment has been minimized.

Copy link

@marti1125 marti1125 commented Feb 3, 2016

nice =D nodejs support es6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.