Const TEXT_DECODER = new TextDecoder();

new to nodejs but getting this error after installing socket.io

/rbd/pnpm-volume/948f344f-98b5-498c-9ce1-0a466f866f88/node_modules/.registry.npmjs.org/engine.io/6.5.0/node_modules/engine.io/build/server.js:16

10:55 PM

const TEXT_DECODER = new TextDecoder();

my server.js below:
const app = require(‘express’)();
const http = require(‘http’).createServer(app);
const io = require(‘socket.io’)(http);

app.get(‘/’, (req, res) => {
res.sendFile(__dirname + ‘/public/index.html’);
});

io.on(‘connection’, (socket) => {
console.log(‘a user connected’);

// Handle chat messages
socket.on(‘chat message’, (message) => {
console.log(message: ${message});
io.emit(‘chat message’, message);
});

// Handle disconnections
socket.on(‘disconnect’, () => {
console.log(‘user disconnected’);
const username = socketMap.get(socket.id);
if (username) {
io.emit(‘chat message’, {
sender: ‘System’,
time: new Date().toLocaleTimeString(),
text: ${username} has left the chat,
});
socketMap.delete(socket.id);
}
});

// Add the user’s username to the socket map
socket.on(‘set username’, (username) => {
console.log(user ${username} connected);
socketMap.set(socket.id, username);
io.emit(‘chat message’, {
sender: ‘System’,
time: new Date().toLocaleTimeString(),
text: ${username} has joined the chat,
});
});
});

// Start the server
const PORT = process.env.PORT || 3000;
http.listen(PORT, () => {
console.log(listening on *http://localhost:${PORT});
});

// Map socket IDs to usernames
const socketMap = new Map();

please help me run this app if it runs i will buy the bigger plan of glitch

that’s the location of the error, not the whole error. it’s missing something like “TextDecoder is undefined.” send a longer snippet of the output

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.