WilliamMabotjaCS227
WilliamMabotjaCS227

Reputation: 97

Unexpected Number : Syntax Error in csv-parser module on Node.js on loading CSV File

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.enter image description here

Upvotes: 0

Views: 580

Answers (1)

Dhruv Shah
Dhruv Shah

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

Related Questions