websockets/ws · error · Error

The server is operating in "noServer" mode

Error message

The server is operating in "noServer" mode

What it means

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.

Solutions

  1. Guard the call: if (!wss.options.noServer) { const addr = wss.address(); }.
  2. In noServer mode, get the address from your own underlying HTTP server that you pass upgrade events from: httpServer.address().
  3. Remove or condition the address() call behind a feature check for the deployment mode.

Example fix

// before
const wss = new WebSocketServer({ noServer: true });
console.log(wss.address());

// after
const wss = new WebSocketServer({ noServer: true });
// use the address of your own HTTP server instead
console.log(httpServer.address());
Defensive patterns

Strategy: validation

Validate before calling

function safeAddress(wss) {
  if (wss.options.noServer) return null;
  return wss.address();
}

Type guard

function canReportAddress(wss) {
  return !wss.options.noServer && !!wss._server;
}

Try / catch

let addr;
try {
  addr = wss.address();
} catch (err) {
  if (/noServer/.test(err.message)) {
    addr = null; // or httpServer.address() from your own server
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of websockets/ws@c791e707ea (2026-08-06). Data as JSON: /api/errors/a47598b53575a2fd. Report an issue: GitHub.

Appendix: source

Thrown at lib/websocket-server.js:155

      this._shouldEmitClose = false;
    }

    this.options = options;
    this._state = RUNNING;
  }

  /**
   * Returns the bound address, the address family name, and port of the server
   * as reported by the operating system if listening on an IP socket.
   * If the server is listening on a pipe or UNIX domain socket, the name is
   * returned as a string.
   *
   * @return {(Object|String|null)} The address of the server
   * @public
   */
  address() {
    if (this.options.noServer) {
      throw new Error('The server is operating in "noServer" mode');
    }

    if (!this._server) return null;
    return this._server.address();
  }

  /**
   * Stop the server from accepting new connections and emit the `'close'` event
   * when all existing connections are closed.
   *
   * @param {Function} [cb] A one-time listener for the `'close'` event
   * @public
   */
  close(cb) {
    if (this._state === CLOSED) {
      if (cb) {
        this.once('close', () => {
          cb(new Error('The server is not running'));

View on GitHub (pinned to c791e707ea)