1

I am trying to load a csv file using d3.csv, I dont know if the node server is the problem or some other code. But its reading the page html instead of the data into the data object Here is the server:

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'html');
  res.end(fs.readFileSync("index.html"));
});

And here is the relevent d3 code:

 d3.csv("./Data/data2.csv").then(function(data) {      
            // format the data

Where data ends up containing the html code : Html code as data

Any suggestions as to why ? Thanks

mike628
  • 45,873
  • 18
  • 40
  • 57
  • This error is very rare and not documented, you can find one or two examples here on SO, and they seem to be related to the server: https://stackoverflow.com/a/36819237/5768908. I suggest you start by checking if you configured your server correctly, for instance, don't you need a `listen()`? – Gerardo Furtado Oct 28 '22 at 00:58
  • If you implement your node server with this request listener, it will always return the index.html file content, no matter what file you request. You should configure your node server to serve static files. Take a look at this documentation: https://nodejs.org/en/knowledge/HTTP/servers/how-to-serve-static-files/ – Cedric Casenove Oct 28 '22 at 06:54

0 Answers0