T
TanStack9mo ago
foreign-sapphire

How to run code when the server starts up?

Hello I am trying to run my drizzle migrations on server startup and also create a cron to do some simple tasks, but I can't find where to put this code. I have already tried using the nitro experimental tasks feature but couldn't get that to run. I will be running this on Bun in a docker container. Any help is appreciated thanks!
7 Replies
subsequent-cyan
subsequent-cyan9mo ago
Any luck with this? Im also wondering if there are any best practices
genetic-orange
genetic-orange9mo ago
The Tanstack team has announced they are moving away from Vinxi (the middleware between Nitro and Start). I'm guessing that once that's done they'll be more deeply integrated with Nitropack and the experimental task feature will work correctly. In the meantime, specifically for migrations, you can run them as a command before server startup: pnpm migrate && pnpm start But I'm also following the thread @drew if you are running a docker container you can also setup a Linux Cron tab in docker if you want.
funny-blue
funny-blue9mo ago
for now i run the migration before running the server, within the docker container
funny-blue
funny-blue9mo ago
funny-blue
funny-blue9mo ago
i have a separate drizzle config for deployment which is stripped down of unnecessary things
statutory-emerald
statutory-emerald9mo ago
can you link where they said this? I'm curious

Did you find this page helpful?