# libgit2.js

> Webassembly port of libgit2 for nodejs and the browser

Latest version **0.0.5** (published 2019-07-02) · 0 weekly downloads

## Install

```sh
npm install libgit2.js
pnpm add libgit2.js
yarn add libgit2.js
bun add libgit2.js
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2019-07-02 |
| First published | 2019-07-01 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Maintainers | petersalomonsen |

## Links

- npm: https://www.npmjs.com/package/libgit2.js
- Repository: https://github.com/fintechneo/libgit2
- Homepage: https://github.com/libgit2/libgit2/pull/4400
- Issues: https://github.com/fintechneo/libgit2/issues
- npm.io page: https://npm.io/package/libgit2.js

## Recent versions

- 0.0.5 (latest) — 2019-07-02
- 0.0.4 — 2019-07-01
- 0.0.3 — 2019-07-01
- 0.0.2 — 2019-07-01
- 0.0.1 — 2019-07-01

## README

WebAssembly port of [libgit2](https://libgit2.org)
==================================================

# Use in the web browser

Initialize a webworker in your html file:
```
<script>
const gitworker = new Worker("git_worker.js");
</script>
```

Copy `libgit2.js` and `libgit2.wasm` from the `node_modules/libgit2.js/` directory into the same folder as `git_worker.js`.

Then in the webworker file `git_worker.js`:

```
importScripts("libgit2.js");
Module['onRuntimeInitialized'] = () => {
    const dir="workdir";
    FS.mkdir(dir,"0777");
    FS.mount(IDBFS, {}, '/'+dir);
    FS.chdir("/"+dir);

    jsgitinit(); // Initialize the library

    jsgitclone("https://somehost/path-to-gitrepository.git","destinationfolder"); // clone a repository
    console.log(FS.readdir("destinationfolder")); // Read the cloned directory contents
};
```

# Use from nodejs

```
const lg = require('libgit2.js');
lg.onRuntimeInitialized = () => {
    const FS = lg.FS;
    const MEMFS = FS.filesystems.MEMFS;

    FS.mkdir('/working');
    FS.mount(MEMFS, { root: '.' }, '/working');
    FS.chdir('/working');

    jsgitinit(); // Initialize the library
    jsgitclone("https://somehost/path-to-gitrepository.git","destinationfolder"); // clone a repository
    console.log(FS.readdir("destinationfolder")); // Read the cloned directory contents
};
```

---
_Source: https://npm.io/package/libgit2.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
