angular/packages/zone.js/test/ws-server.js
Charles Lyding 58d2df8856 test: replace nodejs-websocket package with ws package (#53482)
The `nodejs-websocket` package has been replace with the `ws` package.
Both provide `WebSocket` server support and both of zero transitive
dependencies. However, the `ws` package has ~78 million weekly downloads
and was last updated this week (as of the writing of this commit) while
the `nodejs-websocket` package has ~7,600 weekly downloads and was last
update 5 years ago. The `ws` package is also already a transitive dependency
of the repository which allows for a reduction in the total dependency count
for the repository.

PR Close #53482
2023-12-12 09:01:03 -08:00

19 lines
592 B
JavaScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
const {WebSocketServer} = require('ws');
// simple echo server
const wss = new WebSocketServer({port: 8001});
wss.on('connection', (ws) => {ws.on('message', (data) => {
if (data.toString() === 'close') {
wss.close();
return;
}
ws.send(data);
})});