You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
In "fs.copyFile(src, dest[, mode], callback)" , for callback,'err' is not defined. #53230
import{copyFile,constants}from'node:fs';functioncallback(err){if(err)throwerr;console.log('source.txt was copied to destination.txt');}// destination.txt will be created or overwritten by default.copyFile('source.txt','destination.txt',callback);// By using COPYFILE_EXCL, the operation will fail if destination.txt exists.copyFile('source.txt','destination.txt',constants.COPYFILE_EXCL,callback);
The documentation mentions an err argument in the callback demo code, but no where else in the docs, CC @nodejs/fs
From my test, fs.copyFile's callback has a err param.
$ node test.mjs
file:///test.mjs:4
if (err) throw err;
^
[Error: ENOENT: no such file or directory, copyfile 'source.txt' -> 'destination.txt'] {
errno: -2,
code: 'ENOENT',
syscall: 'copyfile',
path: 'source.txt',
dest: 'destination.txt'
}
Node.js v22.2.0
$ cat test.mjs
import { copyFile } from 'node:fs';
function callback(err) {
if (err) throw err;
console.log('source.txt was copied to destination.txt');
}
// destination.txt will be created or overwritten by default.
copyFile('source.txt', 'destination.txt', callback);
Affected URL(s)
https://nodejs.org/docs/latest/api/fs.html#fscopyfilesrc-dest-mode-callback
Description of the problem
There should be an "err" in the callback function for copyFile model, which is absent. Please do add it..