Here is an example of a complete Node.js script that listens for a response from a WebSocket server:
const WebSocket = require('ws'); const ws = new WebSocket('ws://localhost:8080'); ws.on('open', function() { console.log('WebSocket connection opened'); }); ws.on('message', function(message) { console.log('Received message from server: ' + message); }); ws.on('close', function() { console.log('WebSocket connection closed'); });