{"id":"17b8077b92132f38","repo":"nestjs/nest","slug":"not-initialized-please-call-the-listen-startal-17b807","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-tcp.ts","lineNumber":154,"sourceCode":"  public handleClose(): undefined | number | NodeJS.Timer {\n    if (\n      this.isManuallyTerminated ||\n      !this.getOptionsProp(this.options, 'retryAttempts') ||\n      this.retryAttemptsCount >=\n        this.getOptionsProp(this.options, 'retryAttempts', 0)\n    ) {\n      return undefined;\n    }\n    ++this.retryAttemptsCount;\n    return setTimeout(\n      () => this.server.listen(this.port, this.host),\n      this.getOptionsProp(this.options, 'retryDelay', 0),\n    );\n  }\n\n  public unwrap<T>(): T {\n    if (!this.server) {\n      throw new Error(\n        'Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.',\n      );\n    }\n    return this.server as T;\n  }\n\n  public on<\n    EventKey extends keyof TcpEvents = keyof TcpEvents,\n    EventCallback extends TcpEvents[EventKey] = TcpEvents[EventKey],\n  >(event: EventKey, callback: EventCallback) {\n    if (this.server) {\n      this.server.on(event, callback as any);\n    } else {\n      this.pendingEventListeners.push({ event, callback });\n    }\n  }\n\n  protected init() {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/packages/microservices/server/server-tcp.ts#L136-L172","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-tcp.ts:154 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call app.listen() or app.startAllMicroservices() before accessing the TCP server instance.","Await listen() so the underlying socket server is bound before any access."],"exampleFix":"const app = await NestFactory.createMicroservice(AppModule, opts);\nawait app.listen();\nconst server = app.get(ServerTCP);","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}