[ ] Regression
[ ] Bug report
[X] _Question_
[ ] Feature request
[ ] Documentation issue or request
Does Nest.js have any popular practice for creating external workers? Where you can use all methods from PaymentsService or AccountService. But run worker separately from the main app (For example from PM2 in another process).
I will be grateful if you explain me also how to build this in production. Because of worker maybe can be on another server.
_Current project structure:_
app/
โโโ modules/
โ โโโ account
โ โโโ payments
โโโ workers/
โ โโโ index.js
โ โโโ worker.ts
โโโ app.module.ts
I think what you are looking for are microservices: https://docs.nestjs.com/v5/microservices/basics . Nest already comes with built in transport methods.
Hypothetically you can share the code across microservices, but it's not recommended. Let's say your worker is responsible for sending HTTP requests against an API, why would something but your worker need code for performing the HTTP request?
You could make use of execution context feature which basically allows you creating multiple applications that take advantage of Nest ecosystem. This is explained in the new version of the documentation - https://docs.nestjs.com/v5 (execution context chapter)
Thanks, @kamilmysliwiec, the issue can be closed!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
You could make use of execution context feature which basically allows you creating multiple applications that take advantage of Nest ecosystem. This is explained in the new version of the documentation - https://docs.nestjs.com/v5 (execution context chapter)