> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Drive

> Mount Google Drive as a Mirage filesystem from Node or the browser.

`GDriveVFS` 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 theme={null}
pnpm add @struktoai/mirage-node
```

```ts theme={null}
import { GDriveVFS, MountMode, Workspace } from '@struktoai/mirage-node'

const drive = new GDriveVFS({
  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.shell('ls /drive/')
```

## Browser

```bash theme={null}
pnpm add @struktoai/mirage-browser
```

```ts theme={null}
import { GDriveVFS, MountMode, Workspace } from '@struktoai/mirage-browser'

const drive = new GDriveVFS({
  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.

A Shared Drive is writable on the same terms as My Drive: every Drive call carries `supportsAllDrives`, so what you may change is decided by your role on that drive rather than by the mount, and a role that forbids the change fails with `EACCES` on that operand.

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.