{"id":"f691e11a2fb3c1dc","repo":"nestjs/nest","slug":"not-initialized-please-call-the-listen-startal-f691e1","errorCode":null,"errorMessage":"Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.","messagePattern":"Not initialized\\. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/microservices/server/server-nats.ts","lineNumber":267,"sourceCode":"        case 'update':\n          this.logger.log(\n            `NatsStatus: type: \"${status.type}\", data: \"${data}\".`,\n          );\n          this.statusEventEmitter.emit(NatsEventsMap.UPDATE, status.data);\n          break;\n\n        default:\n          this.logger.log(\n            `NatsStatus: type: \"${status.type}\", data: \"${data}\".`,\n          );\n          break;\n      }\n    }\n  }\n\n  public unwrap<T>(): T {\n    if (!this.natsClient) {\n      throw new Error(\n        'Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.',\n      );\n    }\n    return this.natsClient as T;\n  }\n\n  public on<\n    EventKey extends keyof E = keyof E,\n    EventCallback extends E[EventKey] = E[EventKey],\n  >(event: EventKey, callback: EventCallback) {\n    this.statusEventEmitter.on(event as string | symbol, callback as any);\n  }\n\n  protected initializeSerializer(options: NatsOptions['options']) {\n    this.serializer = options?.serializer ?? new NatsRecordSerializer();\n  }\n\n  protected initializeDeserializer(options: NatsOptions['options']) {","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/packages/microservices/server/server-nats.ts#L249-L285","documentation":"Error \"Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.\" thrown in nestjs/nest.","triggerScenarios":"Thrown at packages/microservices/server/server-nats.ts:267 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call app.listen() or app.startAllMicroservices() before accessing the NATS server instance.","Await the listen promise to guarantee the NATS connection exists before use."],"exampleFix":"const app = await NestFactory.createMicroservice(AppModule, opts);\nawait app.listen();\nconst server = app.get(ServerNats);","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}