A lightweight GitHub content manager for uploading, retrieving, and deleting files from GitHub repositories programmatically.
🔥 Turn any GitHub repository into your personal file server - completely free!
💯 No more costly storage services - leverage GitHub's infrastructure for your file hosting needs
🚀 Simple API to manage your files programmatically - upload, retrieve, and delete with ease
- 🚀 Upload files to GitHub repositories with automatic file naming
- 📥 Retrieve files from repositories with metadata
- 🗑️ Delete files from repositories by name and SHA
- ✅ Built-in validation with Zod
- 📝 TypeScript support
- 🔍 MIME type detection
- 💰 Free file hosting using GitHub's infrastructure
- 🔄 Version control for all your files out of the box
npm install repohub
# or
yarn add repohub
# or
pnpm add repohubimport { createRepHub } from 'repohub';
const repoHub = createRepHub({
ghToken: 'your-github-personal-access-token',
ghRepo: 'your-repository-name',
ghOwner: 'your-github-username'
});// Upload a base64-encoded file
const fileData = await repoHub.upload({
mimeType: 'png', // The file extension without the dot
content: 'base64EncodedContent==', // Must be valid base64
path: 'images' // Optional subfolder
});
console.log(fileData);
// {
// name: 'randomUID.png',
// path: 'images/randomUID.png',
// sha: 'file-sha-hash',
// url: 'github-api-url',
// download_url: 'raw-file-url'
// }// Get file metadata by name
const fileData = await repoHub.get({
name: 'randomUID.png',
path: 'images' // Optional subfolder
});
console.log(fileData);
// {
// name: 'randomUID.png',
// path: 'images/randomUID.png',
// sha: 'file-sha-hash',
// url: 'github-api-url',
// download_url: 'raw-file-url'
// }// Delete a file (requires its SHA)
const result = await repoHub.delete({
name: 'randomUID.png',
path: 'images', // Optional subfolder
sha: 'file-sha-hash' // Required for deletion
});
console.log(result); // "ok"- Completely free - No need to pay for storage services
- Reliable infrastructure - Leverage GitHub's robust platform
- Version control - Every file change is tracked automatically
- Access control - Manage who can access your files using GitHub's permission system
- Public/private options - Choose whether your files are public or private
- No setup required - If you have a GitHub account, you're ready to go
Creates a new RepoHub instance.
options(Object): Configuration optionsghToken(String): GitHub personal access tokenghRepo(String): Repository nameghOwner(String): GitHub username or organization
An object with the following methods:
upload({ mimeType, content, path? }): Upload a new fileget({ name, path? }): Get file metadatadelete({ name, path?, sha }): Delete a file
All methods throw errors for various failure scenarios:
try {
await repoHub.upload({ mimeType: 'png', content: 'invalidBase64' });
} catch (error) {
console.error(error.message);
}- Files are named automatically using a randomly generated UID
- Commit messages are also generated randomly
- Content must be base64 encoded before uploading
- You need a GitHub token with appropriate repository permissions
- Respect GitHub's terms of service and storage limitations
- axios - For HTTP requests
- mrmime - For MIME type detection
- zod - For input validation
MIT