Running a Deno Script with Cron
Deno isn't on cron's minimal PATH, so use the absolute path from `which deno`, and repeat the same `--allow-*` flags you use interactively — cron grants Deno no permissions by default.
The crontab line
0 2 * * * /usr/local/bin/deno run --allow-net --allow-read /opt/app/task.ts >> /var/log/deno-job.log 2>&1
Find the path with which deno — a shell-installed Deno usually lives at ~/.deno/bin/deno, which cron can't see without the full path.
Permission flags are required
Deno is secure-by-default. If your script reads files or hits the network, pass the same flags you use by hand (--allow-net, --allow-read, --allow-env). Missing a flag makes the job exit with a permission error.
Cache directory
Cron has no $HOME, so Deno may re-download deps. Pin the cache with DENO_DIR=/opt/deno-cache at the top of the crontab.
FAQ
How do I run a Deno script from cron?
Use the absolute deno path plus your permission flags: 0 2 * * * /usr/local/bin/deno run --allow-net /opt/app/task.ts. which deno gives you the path.
Why does my Deno cron job fail with a permission error?
Cron runs Deno with no permissions by default. Add the same --allow-net/--allow-read/--allow-env flags you use when running it manually.
Why does Deno re-download dependencies every cron run?
Cron sets no $HOME, so the default cache is lost. Set DENO_DIR to a fixed path in the crontab.