I am trying to copy file from source to destination getting this error
[EISDIR: illegal operation on a directory, copyFile './source/package.json' -> './'] {
code: 'EISDIR',
errno: -21,
path: './source/package.json',
syscall: 'copyFile',
dest: './'
}
don't know where I am doing wrong.
// run `node index.js` in the terminal
const fs = require('fs');
// File destination.txt will be created or overwritten by default.
fs.copyFile('./source/package.json', './', (err) => {
if (err) throw err;
console.log('source.txt was copied to destination.txt');
});
here is my code https://stackblitz.com/edit/node-rwj4vr?file=source%2Fpackage.json,index.js
second concern is can we pass name
attribute to replace this
{
"name":"$name"
}
why this is not working
fs.copyFile('./source/package.json', './dest/package.json', (err) => {
if (err) throw err;
console.log('source.txt was copied to destination.txt');
});
expected it should create dest
folder and put file there
Your problem is that you try to copy the file as a directory ( copyFile ref ) instead of a file, to fix it change the code to:
fs.copyFile('./source/package.json', './package.json', (err) => {
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.