Languages
[Edit]
EN

Node.js - copy file example

0 points
Created by:
Dirask Admin - Marwin
1430

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: 

Node.js - copy file example
Before execution
Node.js - copy file example
After execution

 See also

  1. More copy methods - Node.js - copy files

Node.js - file system module

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join