App reviews, troubleshooting, and recommendations
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Running the shopify app template remix
When running 'npm run dev' or 'shopify app dev' no code inside
- shopify.server.ts
- entry.server.tsc
nor any other file that was defined in https://shopify.dev/docs/apps/build/cli-for-apps/app-structure is run. 'Run' in this case meaning when I add a simple console.log('Hello World!') I can not see it in stdout.
The only file that was actually run when the server started seemed to be '/app/routes.ts' like found here: https://github.com/Shopify/shopify-app-template-remix/blob/main/app/routes.ts. Can someone explain this?
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.
Solved! Go to the solution
This is an accepted solution.
Hello,
for an app development related question, I'd recommend posting on the dev community at https://community.shopify.dev/
As for understanding how a shopify app works, if you haven't done it already I'd recommend that you follow the startup guide at https://shopify.dev/docs/apps/build/scaffold-app Is it what you've done?
Also, getting familiar with how remix works is a must (the file naming convention, the project structure, etc...), all the doc is at https://remix.run/docs/en/main/start/quickstart
For your specific question, you mentioned you want to start a worker process that connects to your pub/sub subscription, right? That can be achieved via a file `shopify.web.toml`. In that file you can tell shopify what to do when you run "shopify app dev", so you'll be able to start a background process from here.
I'd recommend taking a look at the related shopify's documentation just here https://shopify.dev/docs/apps/build/cli-for-apps/app-structure#background-process as it will be explained much better than I can do it!
This is an accepted solution.
Hello,
for an app development related question, I'd recommend posting on the dev community at https://community.shopify.dev/
As for understanding how a shopify app works, if you haven't done it already I'd recommend that you follow the startup guide at https://shopify.dev/docs/apps/build/scaffold-app Is it what you've done?
Also, getting familiar with how remix works is a must (the file naming convention, the project structure, etc...), all the doc is at https://remix.run/docs/en/main/start/quickstart
For your specific question, you mentioned you want to start a worker process that connects to your pub/sub subscription, right? That can be achieved via a file `shopify.web.toml`. In that file you can tell shopify what to do when you run "shopify app dev", so you'll be able to start a background process from here.
I'd recommend taking a look at the related shopify's documentation just here https://shopify.dev/docs/apps/build/cli-for-apps/app-structure#background-process as it will be explained much better than I can do it!
Thank you for the information, I will post it on https://community.shopify.dev/