Websocket server


I’m trying to have a websocket service running on Render Web Service.


I’m getting a connection timeout error when trying to connect to

Do I need to expose WebSocket Port (in this case 5000)? If so, how can I do that?

Here is a similar code to what I’m running:

const WebSocket = require('ws');

const WEB_SOCKET_PORT = process.env.WEBSOCKET_PORT || 5000;

// Create & Start the WebSocket server
const server = new WebSocket.Server({ port: WEB_SOCKET_PORT });

// Register event for client connection
server.on('connection', function connection(ws) {
    // Add the new client to the list of clients
    console.log("new connection", ws)

    ws.on('message', function incoming(data) {
        console.log(`received: ${data}`);
        data = JSON.parse(data)
        data.message = data.data
        const content = JSON.parse(data.data)
        // console.log(content)
        // process content

console.log(`WebSocket server started at port:` + WEB_SOCKET_PORT);

Hello Lucas, I also have a service running WebSockets and I had similar problem as you.

The solution is: You do not need to add the PORT in the URL

Just use: wss://my-service-name.onrender.com

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