// Get some libraries const net = require("net"); // Create a client var client = new net.Socket(); function send_data(client, data) { // Send the data client.write(JSON.stringify(data)); } // Connect to the server client.connect(22068, '127.0.0.1', function() { // Send some data to the server send_data(client, { status: "connected" }); }); client.on('data', function(data) { document.getElementById('server-response').innerHTML = "Response: " + data; }); client.on('close', function(data) { document.getElementById('server-response').innerHTML = "Connection closed"; });