{"id":"a47598b53575a2fd","repo":"websockets/ws","slug":"the-server-is-operating-in-noserver-mode","errorCode":null,"errorMessage":"The server is operating in \"noServer\" mode","messagePattern":"The server is operating in \"noServer\" mode","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/websocket-server.js","lineNumber":155,"sourceCode":"      this._shouldEmitClose = false;\n    }\n\n    this.options = options;\n    this._state = RUNNING;\n  }\n\n  /**\n   * Returns the bound address, the address family name, and port of the server\n   * as reported by the operating system if listening on an IP socket.\n   * If the server is listening on a pipe or UNIX domain socket, the name is\n   * returned as a string.\n   *\n   * @return {(Object|String|null)} The address of the server\n   * @public\n   */\n  address() {\n    if (this.options.noServer) {\n      throw new Error('The server is operating in \"noServer\" mode');\n    }\n\n    if (!this._server) return null;\n    return this._server.address();\n  }\n\n  /**\n   * Stop the server from accepting new connections and emit the `'close'` event\n   * when all existing connections are closed.\n   *\n   * @param {Function} [cb] A one-time listener for the `'close'` event\n   * @public\n   */\n  close(cb) {\n    if (this._state === CLOSED) {\n      if (cb) {\n        this.once('close', () => {\n          cb(new Error('The server is not running'));","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/websockets/ws/blob/ae1de54330cef77e487548890fabfeb9aae1d83d/lib/websocket-server.js#L137-L173","documentation":"Thrown by WebSocketServer.prototype.address() (lib/websocket-server.js:153-160) when the server was constructed in noServer mode. In noServer mode the WebSocketServer owns no underlying net server (this._server is null), so there is no socket address to report; calling address() is meaningless. The guard throws a plain Error (not TypeError) explaining the mode.","triggerScenarios":"Constructing the server with { noServer: true } and later calling wss.address() to discover the bound port/host. This is commonly done after listen for health checks or logging, but in noServer mode the WebSocketServer never bound anything.","commonSituations":"Generic server-status endpoints that call address() on every server in a list; refactoring from port/server mode to noServer mode without removing the address() call; logging code shared across server types.","solutions":["Do not call wss.address() when running in noServer mode; instead query the underlying HTTP server you manage (httpServer.address()).","Guard the call: if (!wss.options.noServer) { const a = wss.address(); }.","Restructure logging to ask the actual listening HTTP server for its address."],"exampleFix":"// before\nconst wss = new WebSocketServer({ noServer: true });\nconsole.log(wss.address());\n\n// after\nconst wss = new WebSocketServer({ noServer: true });\nconsole.log(httpServer.address()); // the real listening socket","handlingStrategy":"type-guard","validationCode":"function safeAddress(wss) {\n  if (wss.options.noServer) return null;\n  return wss.address();\n}","typeGuard":"function canQueryAddress(wss) {\n  return !wss.options.noServer && !!wss._server;\n}","tryCatchPattern":"try {\n  return wss.address();\n} catch (err) {\n  if (/noServer/.test(err.message)) return null;\n  throw err;\n}","preventionTips":["In noServer mode, query the underlying HTTP server (httpServer.address()) instead of wss.address().","Guard address() calls with a noServer check.","Centralize address reporting behind a helper that knows the mode."],"tags":["websocket-server","no-server-mode","configuration","runtime"],"analyzedSha":"ae1de54330cef77e487548890fabfeb9aae1d83d","analyzedAt":"2026-08-03T19:11:18.437Z","schemaVersion":2}