I am new to javascript, and while following a tutorial I came across this code:
const fs = require ('fs')
function readCallback(err, data){
console.log('file read')
}
function copyAll(srcFiles, dest, callback){
for (let i=0; i < srcFiles.length; ++i){
fs.read(srcFiles[i], readCallback)
}
console.log('ending copyAll')
callback()
}
copyAll(['a.txt', 'b.txt', 'c.txt'], 'test', () => console.log('All done'))
console.log('Entering event loop')
However I get the following error message when I run the code:
C:\Users\Syed Hassaan Hasan\Desktop\Assignmnet 2 (AP)>node example.js
buffer.js:113
throw err;
^
TypeError: "size" argument must be a number
at Function.Buffer.allocUnsafe (buffer.js:140:3)
at Object.fs.read (fs.js:658:21)
at copyAll (C:\Users\Syed Hassaan Hasan\Desktop\Assignmnet 2 (AP)\example.js:9:6)
at Object.<anonymous> (C:\Users\Syed Hassaan Hasan\Desktop\Assignmnet 2 (AP)\example.js:15:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
Can somebody please tell me what am I doing wrong and what do I need to learn in order to resolve these errors?
via Hassaan Hasan
No comments:
Post a Comment