Shopify app dev run startup code

Running the shopify app template remix
When running ‘npm run dev’ or ‘shopify app dev’ no code inside

How can I run arbitrary code on my node server using ‘shopify app dev’. Or is that somehow not intended or do I misunderstand the architecture completely?

Even better yet. The first time the code in route.ts is being executed, the .env variable has not been read, so any reads of process.env will result in an undefined. When hot reloading (saving any file, even without changes? CMD+S on mac) and re-executing the code the environment is loaded and all the variables show up as expected.
So this code is not run once per server start but somehow once per hot reload?

PS: What I really want to do is ‘npm run dev’ and then start my gcp pub/sub subscription, pulling/listening on messages. I have not read up on graphql and how that can help with this. Maybe that’s the way to go? Still confused about just calling some code.
Originally posted here Solved: Shopify app dev run startup code - Shopify Community

Hi there :waving_hand:

You may want to look into setting up a custom server for your Remix app.
We have a guide on how to do that here.
That will give you more control over what code runs and when.