https://github.com/manishkumar1601/gitdb
A simple Node.js library to read/write JSON files on GitHub and serve as a lightweight GitDB.
https://github.com/manishkumar1601/gitdb
backend data-storage database esm git gitdb github github-api json json-storage nodejs npm-package octokit open-source typescript
Last synced: 19 days ago
JSON representation
A simple Node.js library to read/write JSON files on GitHub and serve as a lightweight GitDB.
- Host: GitHub
- URL: https://github.com/manishkumar1601/gitdb
- Owner: manishkumar1601
- Created: 2025-05-29T06:34:42.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-05-29T06:37:51.000Z (11 months ago)
- Last Synced: 2025-06-20T11:06:20.580Z (11 months ago)
- Topics: backend, data-storage, database, esm, git, gitdb, github, github-api, json, json-storage, nodejs, npm-package, octokit, open-source, typescript
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GitDB
A simple Node.js library to read/write JSON files on GitHub and serve as a lightweight GitDB.
## Features
- Read JSON file from a GitHub repository
- Write (create/update) JSON file to a GitHub repository
## Installation
```bash
npm install gitdb
```
or
```bash
npm install git+https://github.com/manishkumar1601/gitdb.git
```
## Usage
### CommonJS (Node.js)
```js
const { createDriver, fetchFile, saveFile } = require('gitdb');
const driver = createDriver({
username: 'your-github-username',
repository: 'your-repo-name',
token: 'your-github-personal-access-token',
path: 'data.json', // path in repo
});
fetchFile(driver).then(console.log);
saveFile(driver, { foo: 'bar' }).then(console.log);
```
### ESModule (Node.js ESM or modern bundlers)
```js
import { createDriver, fetchFile, saveFile } from 'gitdb';
const driver = createDriver({
username: 'your-github-username',
repository: 'your-repo-name',
token: 'your-github-personal-access-token',
path: 'data.json',
});
fetchFile(driver).then(console.log);
saveFile(driver, { foo: 'bar' }).then(console.log);
```
### TypeScript
```ts
import { createDriver, fetchFile, saveFile } from 'gitdb';
const driver = createDriver({
username: 'your-github-username',
repository: 'your-repo-name',
token: 'your-github-personal-access-token',
path: 'data.json',
});
fetchFile(driver).then(console.log);
saveFile(driver, { foo: 'bar' }).then(console.log);
```
## API
### createDriver(options)
- `username` (string): GitHub username
- `repository` (string): Repository name
- `token` (string): GitHub personal access token
- `path` (string): File path in the repository (default: `file.json`)
- `message` (string): Commit message (optional)
### fetchFile(driver)
Fetch the JSON file from the repository.
### saveFile(driver, data, extraOptions)
Save (create/update) the JSON file in the repository.
## License
MIT