Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -937,19 +937,20 @@ will be made to remove the destination.
```mjs
import { copyFile, constants } from 'node:fs/promises';

// Example 1: Copy the file, overwriting the destination file if it exists
try {
await copyFile('source.txt', 'destination.txt');
console.log('source.txt was copied to destination.txt');
} catch {
console.error('The file could not be copied');
console.log('File copied successfully: source.txt -> destination.txt');
} catch (err) {
console.error(`Error copying file: ${err.message}`);
}

// By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
// Example 2: By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
try {
await copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
console.log('source.txt was copied to destination.txt');
} catch {
console.error('The file could not be copied');
console.log('File copied successfully: source.txt -> destination.txt');
} catch (err) {
console.error(`Error copying file: ${err.message}`);
}
```

Expand Down