Reputation: 1
const fs = require ('fs'); fs.copyFileSync("file1.txt", "file2.txt");
//when i try to run this code on hyper it gives this error
Error: ENOENT: no such file or directory, copyfile 'file1.txt' -> 'file2.txt' ←[90m at Object.copyFileSync (node:fs:2802:3)←[39m at Object. (C:\Users\ahmad\Desktop\intro-to-node\index.js:2:4) ←[90m at Module._compile (node:internal/modules/cjs/loader:1103:14)←[39m ←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)←[39m ←[90m at Module.load (node:internal/modules/cjs/loader:981:32)←[39m ←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m ←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)←[39m ←[90m at node:internal/main/run_main_module:17:47←[39m { errno: ←[33m-4058←[39m, syscall: ←[32m'copyfile'←[39m, code: ←[32m'ENOENT'←[39m, path: ←[32m'file1.txt'←[39m, dest: ←[32m'file2.txt'←[39m }
Upvotes: 0
Views: 1298
Reputation: 4413
This error tell you that file1.txt does not exists or is not readable.
Check if file1.txt exists. Check if your file1.txt is in the same directory than your node.js script, if not add a path before file1.txt.
Upvotes: 1