0

I have created a nuxt3 application with Prisma database connections. Does Nuxt3 have possibility to run server-side code periodically? I need to run some updates on the database every hour while the application runs>

Tomasz Bawor
  • 1,447
  • 15
  • 40

2 Answers2

1

I don't think this is possible because Nuxt will still ship an SPA at the end of the day, so having something run on a backend will not bring anything on the hydrated client-side app.

Those solutions can help with being notified of a backend change.
Any other approach will require a nuke of the SPA and I can't think of a single use case where that would be a good idea.

Of course, it also depends on the behavior that you expect from your user (opening/closing the tab or just staying on it).

A more traditional MPA framework like Ruby on Rails or PHP without any client-side hydrated app may be a better fit for that exact use-case.

kissu
  • 40,416
  • 14
  • 65
  • 133
  • While using Nuxt3 We have some part of the code that is in the backend like API handling and db connections. I was thinking that maybe I would be able to create some kind of Nitro plugin or something similar that will be run in the "backend" part of the application. I would like to use Nuxt as full stack dev environment. – Tomasz Bawor Dec 19 '22 at 09:24
  • You will still need to loop back from the client to reach out for the backend. An SPA lives in its own client-side realm. I don't think there is a way with a Nitro plugin, but I'm maybe wrong. Have you tried asking on Discord? @TomaszBawor – kissu Dec 19 '22 at 14:13
1

Check out https://github.com/jurassicjs/nuxt-scheduler it looks like it does exactly what you want.

Felix Dolderer
  • 161
  • 2
  • 8