What is GDriveKit?
GDriveKit is a lightweight Google Drive toolkit that makes file management effortless. It provides categorized operation groups for searching, managing folders, and handling files - all with a clean, intuitive API.
Whether you're building a backup system, a file sharing app, or just need to programmatically interact with Google Drive, GDriveKit simplifies the entire process.
Why Use GDriveKit?
The official Google Drive API can be complex and verbose. GDriveKit provides:
- 📁 Categorized Operations - Organized into searchOperations, folderOperations, and more
- 🔐 Simple Token Generation - One-time setup for OAuth credentials
- 📦 Lightweight - Minimal dependencies for faster installs
- 🎯 TypeScript Support - Full type definitions included
- ⚡ Async/Await - Modern Promise-based API
Installation
Get started by installing GDriveKit from npm:
npm install gdrivekitOr with other package managers:
bun add gdrivekit
yarn add gdrivekit
pnpm add gdrivekitOne-Time Setup (Token Generation)
Before you can use Google Drive operations, you must generate access and refresh tokens. This only needs to be done once.
First, set up your Google Cloud credentials:
- Go to Google Cloud Console
- Create a new project and enable the Google Drive API
- Create OAuth 2.0 credentials
- Note your Client ID, Project ID, and Client Secret
Then run the token generation:
import { generateCredentialsAndTokens } from 'gdrivekit';
await generateCredentialsAndTokens({
clientId: process.env.GOOGLE_CLIENT_ID!,
projectId: process.env.GOOGLE_PROJECT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
redirectUris: ['http://localhost:3000/oauth2callback'],
javascript_origin: ['http://localhost:3000'],
});This will open a browser window for you to authorize the application. Once complete, your tokens are saved and you won't need to do this again.
Initializing the Drive Service
After the one-time setup, initialize the service and access operations through categorized groups:
import { initDriveService, operations } from 'gdrivekit';
async function main() {
// Initialize the Drive service
initDriveService();
// Now you can use all operations!
console.log('Drive service initialized');
}
main();Search Operations
GDriveKit provides powerful search capabilities through searchOperations:
Search Files by Name
import { initDriveService, operations } from 'gdrivekit';
initDriveService();
// Search files by name
const files = await operations.searchOperations.searchByName('test');
console.log(files.data?.files);Search with Filters
// Search for specific file types
const pdfs = await operations.searchOperations.searchByName('report', {
mimeType: 'application/pdf'
});
// Search in a specific folder
const folderFiles = await operations.searchOperations.searchByName('document', {
folderId: 'your-folder-id'
});Folder Operations
Manage folders easily with folderOperations:
Get Folder ID by Name
import { initDriveService, operations } from 'gdrivekit';
initDriveService();
// Get folder ID by name
const folderId = await operations.folderOperations.getFolderIdByName('My Documents');
console.log('Folder ID:', folderId);Create a New Folder
// Create a new folder
const newFolder = await operations.folderOperations.createFolder('Backup 2026');
console.log('Created folder:', newFolder.id);List Folder Contents
// List all files in a folder
const contents = await operations.folderOperations.listFolderContents('folder-id');
contents.forEach(file => {
console.log(`- ${file.name} (${file.mimeType})`);
});File Operations
Upload, download, and manage files with fileOperations:
Upload a File
import { initDriveService, operations } from 'gdrivekit';
import fs from 'fs';
initDriveService();
// Upload a file
const fileStream = fs.createReadStream('./document.pdf');
const uploaded = await operations.fileOperations.uploadFile({
name: 'My Document.pdf',
mimeType: 'application/pdf',
body: fileStream,
folderId: 'destination-folder-id' // optional
});
console.log('Uploaded file ID:', uploaded.id);Download a File
// Download a file by ID
const fileContent = await operations.fileOperations.downloadFile('file-id');
// Save to disk
fs.writeFileSync('./downloaded-file.pdf', fileContent);Delete a File
// Delete a file
await operations.fileOperations.deleteFile('file-id');
console.log('File deleted');Real-World Example: File Backup System
Let's build a simple backup utility using GDriveKit:
import { initDriveService, operations } from 'gdrivekit';
import fs from 'fs';
import path from 'path';
async function backupFiles(localDir: string, driveFolder: string) {
// Initialize the service
initDriveService();
// Get or create the backup folder
let folderId = await operations.folderOperations.getFolderIdByName(driveFolder);
if (!folderId) {
const folder = await operations.folderOperations.createFolder(driveFolder);
folderId = folder.id;
}
// Get local files
const files = fs.readdirSync(localDir);
console.log(`Backing up ${files.length} files...`);
for (const fileName of files) {
const filePath = path.join(localDir, fileName);
if (fs.statSync(filePath).isFile()) {
const fileStream = fs.createReadStream(filePath);
await operations.fileOperations.uploadFile({
name: fileName,
body: fileStream,
folderId: folderId
});
console.log(`✓ Uploaded: ${fileName}`);
}
}
console.log('Backup complete!');
}
// Usage
backupFiles('./important-documents', 'My Backups');Environment Variables
For security, store your Google credentials in environment variables:
# .env file
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_PROJECT_ID=your-project-id
GOOGLE_CLIENT_SECRET=your-client-secretThen access them in your code:
import { generateCredentialsAndTokens } from 'gdrivekit';
import 'dotenv/config';
await generateCredentialsAndTokens({
clientId: process.env.GOOGLE_CLIENT_ID!,
projectId: process.env.GOOGLE_PROJECT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
redirectUris: ['http://localhost:3000/oauth2callback'],
javascript_origin: ['http://localhost:3000'],
});Conclusion
GDriveKit makes Google Drive integration simple and organized. With categorized operation groups for searching, folders, and files, you can build powerful file management features with minimal code.
No more wrestling with complex OAuth flows or verbose API calls - just clean, intuitive operations that get the job done.
npm install gdrivekitCheck out the full documentation on npm and start building today!
