An example of how to add a background task (e.g. a queue consumer) to an existing NextJS project.
- Add your background task file
- Add a new
worker-tsconfig.json
, specifically specifying"module": "commonjs"
and targeting only the worker source files. - Add convenience functions for building & running to
package.json
Then to build once:
npm run workers-build
Or to watch source files:
npm run workers-watch
Then to run the worker:
npm run workers-start
@maiconsanson I used Google Cloud for this project when I shared this example. I shared my setup here
https://gist.github.com/babldev/b0e5624dd8b35e999e32301350aaf177
Vercel doesn't have great support for background work afaik. You can trigger an HTTP call in the background via a cron or other mechanism. Just know Vercel gives you 300 seconds max to process.
If you find yourself needing to do something more complex, you probably need to start considering AWS/Google Cloud or something else more flexible than Vercel.