yozawiratama
yozawiratama

Reputation: 4328

How to download file in git repo using nodejs?

I want to download a file in git repo without clone it.
For example lodash git repo :

https://github.com/lodash/lodash/

in that git there is file lodash.js:

https://github.com/lodash/lodash/blob/master/lodash.js

I have try using nodegit but still need to clone all files first.

How to download lodash.js file only in git repo using nodejs?

Upvotes: 6

Views: 9820

Answers (2)

mrvautin
mrvautin

Reputation: 300

You could use download the zip using the direct URL (https://github.com/lodash/lodash/archive/master.zip) and use adm-zip (https://github.com/cthackers/adm-zip) to unzip it locally.

Upvotes: 2

VonC
VonC

Reputation: 1329162

It is easy enough to curl a single file from a git repo

curl -L -O github.com/user/repository/raw/branch/filename

Since you have nodejs, you can use chriso/curlrequest, a node wrapper for curl.

npm install curlrequest
raw.githubusercontent.com/lodash/lodash/master/lodash.js 
curl.request({ url: 'https://raw.githubusercontent.com/lodash/lodash/master/lodash.js' }, function (err, stdout, meta) {
    console.log('%s %s', meta.cmd, meta.args.join(' '));
});

Upvotes: 2

Related Questions