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?
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(' '));
});
您可以使用直接URL( https://github.com/lodash/lodash/archive/master.zip )下载zip,并使用adm-zip( https://github.com/cthackers/adm-zip )在本地解压缩。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.