6

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?

1

2 Answers 2

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(' '));
});
Sign up to request clarification or add additional context in comments.

1 Comment

i dont know why, but curlrequest getting error when download, may be there is other way?
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.