Skip to content

Instantly share code, notes, and snippets.

@sabesansathananthan
Created September 8, 2022 18:58
Show Gist options
  • Save sabesansathananthan/816db9daef602f136bd44092ff0d6279 to your computer and use it in GitHub Desktop.
Save sabesansathananthan/816db9daef602f136bd44092ff0d6279 to your computer and use it in GitHub Desktop.
How to copy files and folders in Node.js?
const { exec, spawn } = require('child_process');
exec('cp ./component/data.txt ./page/info.txt'); // When copying files, you need to make sure the target directory exists
exec('cp -r ./component ./page/landing/home'); // Copy the folder, the target directory can be created automatically
spawn('cp', ['-r', './component', './page/landing/home']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment