docs/ts/develop/running-scripts.md
In local development, you may need to run scripts or commands, such as seeding a database with initial data. For that to work the database needs to be started, and the Encore runtime needs to be configured and initialized.
encore execThe encore exec command allows you to execute custom commands while leveraging Encore's infrastructure setup. This is particularly useful for tasks like database seeding, running scripts, or other one-off commands that require the app's environment to be initialized.
The encore exec command initializes the required infrastructure for your Encore app and executes the specified command.
This ensures that your commands run in the correct context with all dependencies properly configured.
In this example, npx tsx ./seed.ts runs a TypeScript script (seed.ts) to populate the database with initial data
encore exec -- npx tsx ./seed.ts
Here’s what happens:
npx tsx ./seed.ts command is executed in the context of the initialized app.encore exec -- <your-command>
Substitute <your-command> with the specific command you wish to run.
-- to separate encore exec options from the command you want to run.