'How to run one off tasks in NestJS

I'm new to NestJS and i'm trying to figure out the best way to run one off initialization tasks and import tasks. In Rails you would use Rake to run the tasks, but i'm not sure what to use here. I see things like nest-commander and nestjs-cli, but those seem like you need to setup another app instance to make it work and i'm not sure if that's the proper way to handle it. I've seen other tools like Jake as well, but I would need access to my NestJS modules in the tasks. Anyone find a good way to handle this or have an example of how it's been handled well in a project?



Solution 1:[1]

In this case what I would probably do is

  • create a module with a service.
  • create methods that does things for you
  • should have a init method that could initiate the task
  • use a test to compile this module and run the test for the service method that initiates the task.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rohit Gupta