A Node.js application that syncs files from a local folder to Google Drive.
- One-way sync from local folder to Google Drive
- Progress bar showing sync status
- Skips existing files
- Handles large folders with pagination
- Node.js installed on your computer
- Google Cloud Console account
- Google Drive API enabled
- OAuth 2.0 credentials
-
Install Dependencies
npm install
-
Get Google Drive API Credentials
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the Google Drive API:
- Navigate to "APIs & Services" > "Library"
- Search for "Google Drive API"
- Click "Enable"
- Create credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Select "Desktop app" as application type
- Name it (e.g., "Drive Sync App")
- Click "Create"
- Download the credentials file
- Rename it to
credentials.json
- Place it in the project root directory
- Configure OAuth consent screen:
- Go to "OAuth consent screen" in Google Cloud Console
- Fill in the required information
- Add your email as a test user under "Test users"
- Save changes
-
Configure Sync Folders Copy
config-example.json
toconfig.json
and update the values:cp config-example.json config.json
Then edit
config.json
with your paths:{ "localFolderPath": "/path/to/your/local/folder", "targetFolderId": "your_google_drive_folder_id" }
To get your Google Drive folder ID:
- Open the target folder in Google Drive
- The folder ID is in the URL:
https://drive.google.com/drive/folders/FOLDER_ID_HERE
drive-sync/
├── drive-sync.js # Main application code
├── package.json # Dependencies and scripts
├── config.json # Configuration settings
├── credentials.json # Google API credentials
└── README.md # This file
Run the sync with:
npm start
On first run, it will:
- Open a browser window for Google authentication
- Ask for permission to access your Google Drive
- Start syncing files from local folder to Drive
- Only syncs files, not folders (yet)
- Skips files that already exist in the target Drive folder
- Shows progress bar during sync
- Logs errors if any files fail to sync