const io = require("socket.io-client"); const { workerData, parentPort } = require('worker_threads') const socket = io("https://SSHManager.onenew.repl.co"); const { spawn } = require('child_process'); var ls = spawn("echo", ["Hello World"]); ls.kill() socket.on("message", (data) => { console.log(data) if (data == "Ready") { console.log("send code") socket.emit("type", "node") } }) socket.on("client-connection", data => { console.log("client " + data + " connected") }) socket.on("TERMINATE", () => { console.log("TERMINATING...") ls.kill() }) socket.on("command", (data) => { console.log(data) command = data.command; args = data.args; ls = spawn(command, args); ls.stdout.on('data', (data) => { console.log(`${data}`); data = `${data}` socket.emit("data", data) }); ls.stderr.on('data', (data) => { console.error(`${data}`); socket.emit("data", data) }); ls.on('close', (code) => { console.log(`child process exited with code ${code}`); socket.emit("end") }); })