Running a Bun Script with Cron
Bun installs to `~/.bun/bin`, which isn't on cron's PATH — call it by absolute path, and `cd` into the project first if the script reads a local `package.json` or `bun.lockb`.
The crontab line
0 2 * * * cd /opt/app && /root/.bun/bin/bun run task.ts >> /var/log/bun-job.log 2>&1
Run which bun to confirm the path. It is almost always under $HOME/.bun/bin/bun, so substitute the right home directory for the cron user.
cd into the project
If you call a package.json script (bun run build) or import relative files, cd into the project directory first — cron starts in the user's home, not your repo.
Running a package script
bun run <script> works the same as npm. For a one-off file just pass the path: bun /opt/app/task.ts.
FAQ
How do I run Bun from a cron job?
Use the absolute path, e.g. 0 2 * * * cd /opt/app && /root/.bun/bin/bun run task.ts. Find it with which bun.
Why is bun not found in cron?
Bun installs to ~/.bun/bin, which is added to PATH only in your shell profile that cron doesn't load. Use the full path.
Do I need to cd before running bun in cron?
Yes if the script reads package.json, bun.lockb, or relative files — cron's working directory is the home dir, not your project.