EN
Node.js - copy file example
0
points
In this article, we would like to show you how to copy files in Node.js.
Practical example
const { copyFile } = require('fs/promises');
const copyFileAsync = async (sourcePath, destinationPath) =>{
try {
await copyFile(sourcePath, destinationPath);
console.log('copied successfully!');
} catch (error) {
console.log(error);
}
}
copyFileAsync('C:/path/to/file.txt', 'C:/path/to/file_copy.txt');
Result:
See also
- More copy methods - Node.js - copy files