5

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?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
yozawiratama
  • 4,209
  • 12
  • 58
  • 106
  • Can't you just use the github raw url !? E.g. https://raw.githubusercontent.com/lodash/lodash/master/lodash.js – René Link Jan 05 '16 at 10:31

2 Answers2

2

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(' '));
});
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

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.

mrvautin
  • 190
  • 1
  • 10