I am trying to copy content from one file to another but node throws an error. I have no idea. Could you help?
I have entered the syntax for copyFile but it is not working.
Is it because of version or something else?
const fs = require('fs');
fs.copyFile('filel.txt', 'file2.txt');
$ node index.js
node: internal/validators:421
throw new ERR_INVALID_ARG_TYPE(name,
'Function', value);
MINGW64:/c/Users/HP/Desktop/intro-to-node
TypeError [ERR_INVALID_ARG_TYPE]: The "cb" argument must be of type function. Received undefined
at makeCallback (node:fs:195:3)
at Object.copyFile (node:fs:2841:14)
at Object. ‹anonymous> (C: \Users\HP\Desktop\intro-to-node\index.js:4:4) at Module,_compile (node: internal/modules/cjs/loader: 1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10) at Module.load (node: internal/modules/cjs/loader:1081:32)
at Module._load (node: internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as ruMain] (node: internal/modules/run_main:81:12)
at node: internal/main/run_main_module:23:47 {
code: 'ERR_INVALID_ARG_TYPE'
Node. js v18.13.0
You need to use fs.copyFileSync