When you want using same code base for multiple services.

  1. Create new json file nest-cli-worker.json in the root folder
{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "entryFile": "worker-main",
  "watchAssets": true,
  "deleteOutDir": true,
  "compilerOptions": {}
}
  1. Build is the same but start command is difference package.json
    "worker:start:dev": "cp env.local.sh .env && nest start --config nest-cli-worker.json --debug --watch",
    "worker:start:prod": "node dist/worker-main",

Note:

[_] Note to using difference port if you want to running multiple services at once

This post is imported from: https://thebrownbox.hashnode.dev/start-with-a-specific-file-in-nestjs