Clone Git Repositories In Memory

node v14.20.1
version: master
endpointsharetweet
Clone Git repositories in-memory using pure Node.js! (no Git binary, no FS) We will use isomorphic-git (https://github.com/isomorphic-git/isomorphic-git) and memfs (https://github.com/streamich/memfs). First let's import everything and create a new in-memory file system.
const git = require("isomorphic-git"); const http = require("isomorphic-git/http/node"); const { Volume, createFsFromVolume } = require("memfs"); const vol = new Volume(); const fs = createFsFromVolume(vol); undefined;
Now let's clone a public GitHub repository into the root directory:
await git.clone({ fs, http, dir: '/', url: 'https://github.com/iddan/react-spreadsheet', ref: 'master', singleBranch: true, depth: 1, });
Now we can list the files in the repository:
await fs.promises.readdir("/");
And read a file:
await fs.promises.readFile('/package.json', 'utf-8');
Loading…

no comments

    sign in to comment