Welcome folks today in this blog post we will be downloading github repository
and save it in folder
from url using child process
module in node.js. All the full source code of the application is shown below.
Get Started
In order to get started you need to make a new node.js
project using the below command as shown below
npm init -y
Now we need to make the index.js
file and copy paste the following code
index.js
1 2 3 4 5 6 7 8 9 10 11 12 |
const { exec } = require('child_process'); const downloadUrl = 'https://github.com/gauti123456/GmailInbox'; const destinationFolder = 'public'; exec(`git clone ${downloadUrl} ${destinationFolder}`, (error, stdout, stderr) => { if (error) { console.error(`exec error: ${error}`); return; } console.log(`stdout: ${stdout}`); console.error(`stderr: ${stderr}`); }); |
As you can see we are importing the child_process
module at the top and then we are providing the url
of the github repository and then we are providing the location where the repository
will be downloaded inside the public
folder and then we are using the exec()
method and passing the git clone
command and then automatically all the files will be downloaded as shown below