Reputation: 1070
Im using nodejs to write on a file.
fs.open(path.join(reportPath), 'a', 666, ( e, fd ) => {
fs.write( fd, `There is a company named ${companyName}` + os.EOL, null, 'utf8', () => {
fs.close( (err) => {
if(err) throw err;
console.log('write successfull')
})
})
})
Its returning an error, actually the file are written but the error make my server stop. because of the throw err
here the error message:
TypeError: fd must be a file descriptor
at Object.fs.close (fs.js:608:11)
at C:\DATA\source\code\build\modules\desc\controller.js:199:42
at FSReqWrap.wrapper [as oncomplete] (fs.js:685:5)
Upvotes: 0
Views: 1663
Reputation: 1070
I forgot to pass an file-descriptor on fs.close()
fs.open(path.join(reportPath), 'a', 666, ( e, fd ) => {
fs.write( fd, `There is a company named ${companyName}` + os.EOL, null, 'utf8', () => {
fs.close(fd, (err) => {
if(err) throw err;
console.log('write successfull')
})
})
})
Upvotes: 2