ENAMETOOLONG on request for xml document

node.js, request, rss, stream, xml

Solution

You're trying to create a ReadableStream from a file on disk by using the body of the HTTP request (ie. the content of your XML file) as the file name.

What you mean is:

request.get(feed, function(error, response) {
  if (!error && response.statusCode == 200) {
    response.pipe(someXmlParserStream);
  }
});

which takes advantage of the fact the `response` object is already a Readable stream, that you can pipe to another stream.

If you don't want to use streams, but instead buffer the whole body, then `request` can do that for you:

request.get(feed, function(error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
});

Problem

I am trying to fetch my RSS data feed (xml file) via `node`'s request module as follows: ``` var fs = require('fs') , request = require('request') , feed = 'http://www.benchmark.pl/rss/aktualnosci-pliki.xml'; request.get(feed, function(error, response, body) { if (!error && response.statusCode == 200) { var csv = body; fs.createReadStream(body) .on('error', function (error) { console.error(error); }); } }); ``` But I am getting the error : ``` { [Error: ENAMETOOLONG, open '<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> <channel> <title> .... </rss> ``` What should I do in this situation ?

Original source