{"library":"nestjs-temporal","title":"Temporal for NestJS Framework","description":"nestjs-temporal is an integration module that seamlessly connects the Temporal TypeScript SDK with the NestJS framework. It simplifies the process of developing scalable, fault-tolerant applications by allowing developers to define Temporal Workflows and Activities using NestJS's decorator-based and dependency injection patterns. The current stable version, 2.1.0, actively supports a wide range of NestJS versions from 8.x to 11.x, indicating robust maintenance and compatibility. This module differentiates itself by providing a first-class NestJS experience for Temporal development, abstracting much of the underlying Temporal SDK setup and configuration into familiar NestJS modules, providers, and decorators. While a specific release cadence isn't published, its frequent updates to support new NestJS versions suggest ongoing development and commitment to keeping pace with the NestJS ecosystem. It's a critical component for NestJS projects requiring durable execution and complex long-running business processes facilitated by Temporal.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install nestjs-temporal"],"cli":null},"imports":["import { TemporalModule } from 'nestjs-temporal';","import { Activities, Activity } from 'nestjs-temporal';","import { InjectTemporalClient } from 'nestjs-temporal';","import { WorkflowClient } from '@temporalio/client';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"/* src/main.ts */\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\n\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule);\n  await app.listen(3000);\n}\nbootstrap();\n\n/* src/app.module.ts */\nimport { Module } from '@nestjs/common';\nimport { TemporalModule } from 'nestjs-temporal';\nimport { AppController } from './app.controller';\nimport { GreetingActivity } from './activities/greeting.activity';\n\n@Module({\n  imports: [\n    TemporalModule.registerWorker({\n      workerOptions: {\n        taskQueue: 'default',\n        // Ensure this path is correct for your compiled JS output in production\n        workflowsPath: require.resolve('./temporal/example.workflow'),\n      },\n    }),\n    TemporalModule.registerClient(),\n  ],\n  controllers: [AppController],\n  providers: [GreetingActivity],\n})\nexport class AppModule {}\n\n/* src/activities/greeting.activity.ts */\nimport { Injectable } from '@nestjs/common';\nimport { Activities, Activity } from 'nestjs-temporal';\n\n@Injectable()\n@Activities()\nexport class GreetingActivity {\n  @Activity()\n  async greeting(name: string): Promise<string> {\n    return 'Hello ' + name;\n  }\n}\nexport interface IGreetingActivity {\n  greeting(name: string): Promise<string>;\n}\n\n/* src/temporal/example.workflow.ts */\nimport { proxyActivities } from '@temporalio/workflow';\nimport { IGreetingActivity } from '../activities/greeting.activity';\n\nconst { greeting } = proxyActivities<IGreetingActivity>({\n  startToCloseTimeout: '1 minute',\n});\n\nexport async function example(name: string): Promise<string> {\n  return await greeting(name);\n}\n\n/* src/app.controller.ts */\nimport { Controller, Post, Get } from '@nestjs/common';\nimport { WorkflowClient } from '@temporalio/client';\nimport { InjectTemporalClient } from 'nestjs-temporal';\n\n@Controller('temporal')\nexport class AppController {\n  constructor(\n    @InjectTemporalClient() private readonly temporalClient: WorkflowClient,\n  ) {}\n\n  @Post('greet')\n  async startGreetingWorkflow() {\n    const workflowId = `greeting-workflow-${Date.now()}`;\n    const handle = await this.temporalClient.start('example', {\n      args: ['Temporal User'],\n      taskQueue: 'default',\n      workflowId,\n    });\n    console.log(`Started workflow ${workflowId}`);\n    return { workflowId: handle.workflowId, result: await handle.result() };\n  }\n\n  @Get('health')\n  getHealth() {\n    return { status: 'ok' };\n  }\n}\n","lang":"typescript","description":"This quickstart demonstrates how to set up a basic NestJS application using `nestjs-temporal` to define and execute a Temporal workflow. It includes registering a Temporal worker and client, defining an activity service with a greeting activity, creating a simple workflow that calls the activity, and exposing an API endpoint to start the workflow.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}