Nest: How to use Nest Services in another App

Created on 6 May 2018  ยท  4Comments  ยท  Source: nestjs/nest


[ ] Regression
[ ] Bug report
[X] _Question_
[ ] Feature request
[ ] Documentation issue or request

What is the motivation?

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

question ๐Ÿ™Œ

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)

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hypeofpipe picture hypeofpipe  ยท  27Comments

galkowskit picture galkowskit  ยท  45Comments

artjomzab picture artjomzab  ยท  33Comments

chaostheory picture chaostheory  ยท  34Comments

raydirty picture raydirty  ยท  37Comments