Reputation: 625
My simple script easily reads data from local csv files:
const csv = require('csv-parse');
const fs = require('fs');
const file = './files/projects.csv';
const run = () => {
fs.createReadStream(file)
.pipe(
csv({
trim: true,
columns: true,
delimiter: ',',
skip_empty_lines: true
})
)
.on('data', row => {
console.log('***', row)
})
};
run();
how I can read in the same way data from csv files which are not stored locally and have url address like "https://example.com/files/project.csv"?
Thank you in advance <3
Upvotes: 2
Views: 3313
Reputation: 756
You can pipe http request responses in a similar way to file streams. This code fetches a file from https://example.com/example.csv
. (I think)
var http = require("http"); //HTTP module
var csv = require('csv-parse'); //CSV module
var url = "https://example.com/example.csv";
http.request(url, response => { //Make request to URL
response.pipe(
//YOUR CODE
csv({
trim: true,
columns: true,
delimiter: ',',
skip_empty_lines: true
})
).on('data', row => {
console.log('***', row)
});
}).end();
Upvotes: 3