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() (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.
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 ae1de54330)
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.
Example fix
// before
const wss = new WebSocketServer({ noServer: true });
console.log(wss.address());
// after
const wss = new WebSocketServer({ noServer: true });
console.log(httpServer.address()); // the real listening socket Defensive patterns
Strategy: type-guard
Validate before calling
function safeAddress(wss) {
if (wss.options.noServer) return null;
return wss.address();
} Type guard
function canQueryAddress(wss) {
return !wss.options.noServer && !!wss._server;
} Try / catch
try {
return wss.address();
} catch (err) {
if (/noServer/.test(err.message)) return null;
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- One and only one of the "port", "server", or "noServer" opti
- server.handleUpgrade() was called more than once with the sa
- Unsupported protocol version: ${opts.protocolVersion} (suppo
AI-assisted analysis of websockets/ws@ae1de54330 (2026-08-03).
Data as JSON: /data/errors/a47598b53575a2fd.json.
Report an issue: GitHub.