Repeating readstreams successfully

32 Views Asked by At

I am using csv-parser to parse a csv I have gotten from a POST request. The problem is, that after I restart the nodeserver, It only manages to parse the first csv from the first submission of the POST form, not any of the next ones. I am moving the file from the request to a temporary location right before i try to parse it, in case that makes a difference.

the following code is executed after a POST reqest has been recieved.

    let fil = req.files['csv'];

    let filePath = path.join(__dirname, '../filer/tmp.csv');

    await fil.mv(filePath, (err) => {
        if(err) {
            console.log("move_err: " + err)
        }
    })

    await fs.createReadStream(filePath)
        .pipe(csv({separator: ';'}))
        .on('data', (data) => console.log(data))
        .on('end', () => console.log('done'))
        .on('error', (err) => console.log(err));

Any help is appriciated

0

There are 0 best solutions below