Languages
[Edit]
EN

Node.js - copy file example

0 points
Created by:
Geospatial-Palus
630

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
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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