---
title: Google Drive
icon: google
description: Mount Google Drive as a Mirage filesystem from Node or the browser.
---

`GDriveResource` exposes a user's Drive (My Drive plus shared drives the user can see) as a tree.

Setup steps for OAuth credentials live at [Google Workspace Credentials](/home/setup/google).

## Node

```bash
pnpm add @struktoai/mirage-node
```

```ts
import { GDriveResource, MountMode, Workspace } from '@struktoai/mirage-node'

const drive = new GDriveResource({
  clientId: process.env.GOOGLE_CLIENT_ID!,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
  refreshToken: process.env.GOOGLE_REFRESH_TOKEN!,
})

const ws = new Workspace({ '/drive': drive }, { mode: MountMode.WRITE })
await ws.execute('ls /drive/')
```

## Browser

```bash
pnpm add @struktoai/mirage-browser
```

```ts
import { GDriveResource, MountMode, Workspace } from '@struktoai/mirage-browser'

const drive = new GDriveResource({
  clientId: GOOGLE_CLIENT_ID,
  clientSecret: GOOGLE_CLIENT_SECRET,
  refreshToken: localStorage.getItem('gdrive.refresh_token')!,
})

const ws = new Workspace({ '/drive': drive }, { mode: MountMode.WRITE })
```

The browser examples in `examples/typescript/browser/src/gdrive_pkce.ts` show a full PKCE flow that keeps the secret out of the page.

## Config

| Field | Default | Notes |
| --- | --- | --- |
| `clientId` | required | Google OAuth client ID. |
| `clientSecret` | required | Google OAuth client secret. Redacted in snapshots. |
| `refreshToken` | required | User's refresh token. Redacted in snapshots. |
| `refreshFn` | built-in | Optional override for the access-token refresh callback. |
| `folderId` | unset | Mount a single folder as the root instead of the whole Drive. The folder may live in My Drive or inside a Shared Drive (drive scope resolves automatically); other shared drives are not surfaced on scoped mounts. |

## Mount mode

`read` and `write`. Under write mode the standard write commands (`tee`, `cp`, `mv`, `rm`, `mkdir`, `sed -i`, ...) work on regular files and folders; Google-native files (`.gdoc.json`, `.gsheet.json`, `.gslide.json`) are mutated through the `gws` commands instead.

For the mounted layout, the `gws` command reference, and snapshot behavior see the [Python Drive docs](/python/resource/gdrive).
