I am working through a D3 example where I have to read a data.csv file with it.
I have downloaded and set up Node.js, next I have created a server with this code, and it works great.
var http = require('http');
var fs = require('fs');
var server = http.createServer(function(request, response){
response.writeHead(200, {
'Content-Type' : 'text-html'
});
fs.readFile('data.csv', 'utf8', function (err, text ){
response.end(text);
});
});
server.listen(3000, function () {
console.log('Server is listening at http://localhost:3000');
});
But .. this does not work. d3.csv does not like it, or there is some browser issue, or something else.
<script>
myArrayOfObjects.forEach(function (d){
console.log(d.x + ", " + d.y);
});
});
</script>
For this situation, this what I get from the Chrome Console:
XMLHttpRequest cannot load http://localhost:3000/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.