Reputation: 97
I am getting a Syntax Error Whilst Reading a CSV file with FS module and csv-parser.
When I do the same process without using it in a REST API, it works just fine, even console.logs to the screen.
The error came about when I was sending the data over the network in a REST API.
Find the Screenshots attached.
Upvotes: 0
Views: 580
Reputation: 1661
According to the documentation of createReadStream
, it expects the path to the file rather than the file
itself.
Hence, on line 7
, change it to :
const dataPath = path.resolve(__dirname, './data/metering_data.csv);
And then read the file using createReadStream
as fs.createReadStream(dataPath);
Make sure you've imported the path
module at the start of your file as following:
var path = require('path')
Upvotes: 1