Copy a file
fs.copyFileSync() (when available) in the synchronous version.$ npm install cp-file
const cpFile = require('cp-file');
(async () => {
await cpFile('source/unicorn.png', 'destination/unicorn.png');
console.log('File copied');
})();
Returns a Promise that resolves when the file is copied.
Type: string
File you want to copy.
Type: string
Where you want the file copied.
Type: Object
Type: boolean
Default: true
Overwrite existing file.
Progress reporting. Only available when using the async method.
Type: Function
{
src: string,
dest: string,
size: number,
written: number,
percent: number
}
src and dest are absolute paths.size and written are in bytes.percent is a value between 0 and 1.progress event is emitted only once..on() method is available only right after the initial cpFile() call. So make surehandler before .then():(async () => {
await cpFile(source, destination).on('progress', data => {
// …
});
})();
MIT © Sindre Sorhus