{"record":{"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/c791e707eab3c13dd9a261d2479c3cc4a49a6fed/lib/websocket-server.js#L137-L173","documentation":"Thrown by WebSocketServer.prototype.address() at websocket-server.js:154-156 when the server was created with noServer: true. In noServer mode the WebSocketServer does not own or wrap any underlying net/http server (this._server is never set), so there is no socket address to report. The method guards against this misuse rather than returning undefined.","triggerScenarios":"Calling wss.address() on a server constructed with { noServer: true }. Because noServer mode means you handle the 'upgrade' event yourself and there is no this._server, the check at line 154 throws before the null check at line 158.","commonSituations":"Copying logging/health-check code from a port-mode or server-mode example into a noServer deployment; a generic monitoring middleware that calls .address() on any server-like object; refactoring from server mode to noServer without updating diagnostics.","solutions":["Guard the call: if (!wss.options.noServer) { const addr = wss.address(); }.","In noServer mode, get the address from your own underlying HTTP server that you pass upgrade events from: httpServer.address().","Remove or condition the address() call behind a feature check for the deployment mode."],"exampleFix":"// before\nconst wss = new WebSocketServer({ noServer: true });\nconsole.log(wss.address());\n\n// after\nconst wss = new WebSocketServer({ noServer: true });\n// use the address of your own HTTP server instead\nconsole.log(httpServer.address());","handlingStrategy":"validation","validationCode":"function safeAddress(wss) {\n  if (wss.options.noServer) return null;\n  return wss.address();\n}","typeGuard":"function canReportAddress(wss) {\n  return !wss.options.noServer && !!wss._server;\n}","tryCatchPattern":"let addr;\ntry {\n  addr = wss.address();\n} catch (err) {\n  if (/noServer/.test(err.message)) {\n    addr = null; // or httpServer.address() from your own server\n  } else throw err;\n}","preventionTips":["Check wss.options.noServer before calling wss.address().","In noServer mode, report the address of your own underlying HTTP server instead.","Keep diagnostic/health-check code mode-aware."],"tags":["websocket-server","noserver","configuration","api-misuse"],"backgroundTag":null,"analyzedSha":"c791e707eab3c13dd9a261d2479c3cc4a49a6fed","analyzedAt":"2026-08-06T19:07:51.047Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}