Skip to main content

Command Palette

Search for a command to run...

Running Convex Functions from the CLI

Published
1 min read
Running Convex Functions from the CLI
T

Just a guy who loves to write code and watch anime.

Basic syntax

npx convex run <fileName>:<functionName>

Dev vs Production

# Dev (default)
npx convex run migrations:backfillUsers

# Production
npx convex run migrations:backfillUsers --prod

With arguments

Pass a JSON string as the second argument.

npx convex run migrations:backfillUsers '{"batchSize": 100}'
npx convex run migrations:backfillUsers '{"batchSize": 100}' --prod

Internal functions

Works the same. The CLI can call internal functions even though clients cannot.

# convex/migrations.ts exports an internalMutation called backfillUsers
npx convex run migrations:backfillUsers
npx convex run migrations:backfillUsers --prod

Queries and actions too

Not limited to mutations. Run any Convex function.

npx convex run posts:listAll
npx convex run ai:generateSummary '{"postId": "abc123"}'

Use cases

  • One-off migrations and backfills

  • Data fixes in dev or production

  • Seeding dev data

  • Testing internal functions manually

  • Running cleanup scripts