ryu1kn / csv-writer

Convert objects/arrays into a CSV string or write them into a CSV file
https://www.npmjs.com/package/csv-writer
MIT License
246 stars 39 forks source link

Can't save file in windows 10. #33

Closed umerchaudhary34 closed 4 years ago

umerchaudhary34 commented 4 years ago
      const date = new Date().toISOString().split('T')[0];
      const csvWriter = createCsvWriter({
        path: `${require('path').join(require('os').homedir(), 'Desktop')}/${city}-${date}.csv`,
        header: [
          {id: 'name', title: 'name'},
          {id: 'status', title: 'status'},
          {id: 'registration', title: 'registration'},
          {id: 'city', title: 'city'},
          {id: 'prov', title: 'prov'},
          {id: 'phone', title: 'phone'},
          {id: 'distance', title: 'distance'},
          {id: 'clinic', title: 'clinic'},
        ]
      });

        csvWriter
        .writeRecords(data)
        .then(()=> {
          console.log(`The ${city}-${date}.csv file was written successfully`)
          win.webContents.send('ping', `done ${city}-${date}.csv file was written successfully`);
        }
        ).catch(err=> {
          console.log(err)
          win.webContents.send('ping', `Couldn't save file, please restart process`);
        })

i am using abpove code to write a file to desktop , it works for macOS but doesn't works on windows 10, getting following error on windows

[Error: ENOENT: no such file or directory, open 'C:\Users\Dell\Desktop\vancouver-2019-12-27.csv'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\Users\\Dell\\Desktop\\vancouver-2019-12-27.csv'
}
umerchaudhary34 commented 4 years ago

Windows desktop is at different path -_-

DianaLaa commented 1 year ago

I'm having the same issue, could you explain how I should specify the path?

sureshkodur commented 1 year ago

Any resolution for this issue? I have the similar issue. I'm using it inside an azure function to export csv. It is giving me similar error file not found.