Answer the question
In order to leave comments, you need to log in
Why can't I send the request again?
I'm using node-feedparser . The code is something like this:
const request = require('request'),
feedParser = require('feedparser');
feedParser.on('readable', function() {
var stream = this, item = stream.read();
if (item) {
//код для работы с данными
}
});
this.feedParser.on('end', () => {
console.log('end');
});
const req = this.request(url), $this = this;
req.on('response', function(res) {
req.pipe(feedParser);
});
Answer the question
In order to leave comments, you need to log in
Is it really that hard to read the description of a module on npmjs.org?
const request = require('request');
const FeedParser = require('feedparser');
function readFeed(url) {
return new Promise((resolve, reject) => {
const $this = this;
const feedParser = new FeedParser();
const req = this.request(url);
feedParser.on('readable', function() {
var stream = this, item = stream.read();
if (item) {
//код для работы с данными
}
});
this.feedParser.on('end', () => {
resolve();
});
feedParser.on('error', reject);
req.on('response', function(res) {
req.pipe(feedParser);
});
req.on('error', reject);
});
}
readFeed('url').then(() => {
console.log('end');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question