'How do I make my code write messages to the terminal?

For an assignment I need to make a chat client in the terminals, but my code won't write to the terminals. I believe it might have something to do .write not working as intended as it should write to each terminal, but doesn't write anything.

const { fstat } = require('fs');
const net = require('net');

let guest = 1;
let clients = [];

let server = net.createServer(client => {
    client.write(`welcome guest`)
    client.userName = 'Guest'+ guest++;
    clients.push(client)
    clients.forEach(element => {
        element.write(`welcome ${client.userName}`)
    });
    client.setEncoding('utf8')
    client.on('data', (message) => {
        if(isCommand(message)) {
            clients.forEach(element => {
                if (element != client.userName)
                element.write(`${client.userName}: ${message}`)
    });
}).listen(2000);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source