0

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

1 Answer 1

1

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')

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Sir! The Error was fixed my API is working accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.