Package Information
Documentation
n8n-nodes-websocket-standalone
This is a node package for n8n that adds standalone WebSocket server functionality to your workflows. It provides WebSocket Trigger and Response nodes that allow you to create independent WebSocket servers and handle real-time communication in your n8n workflows.
Features
- ๐ WebSocket Trigger node to start workflows on WebSocket messages
- ๐ค WebSocket Response node to send messages back to clients
- ๐ Standalone WebSocket server implementation (no dependency on n8n's HTTP server)
- ๐ข Custom port configuration for each WebSocket server
- ๐ฃ๏ธ Custom path configuration for WebSocket endpoints
- ๐ Robust connection handling with automatic ping/pong keep-alive
- ๐ Connection persistence between trigger and response nodes
- ๐งช Enhanced stability for testing and production workflows
Installation
In n8n:
- Go to Settings > Community Nodes
- Select Install
- Enter
n8n-nodes-websocket-standalonein Enter npm package name - Click Install
Manual Installation:
npm install n8n-nodes-websocket-standalone
Usage
WebSocket Trigger Node
- Add a "WebSocket Trigger" node to your workflow
- Configure the port (default: 5680) and path (default: /ws)
- Optionally set a custom connection ID
- The node will create a WebSocket server at
ws://localhost:{port}{path} - When a message is received, the workflow will be triggered with the message data
WebSocket Response Node
- Add a "WebSocket Response" node after your processing nodes
- Configure how to obtain the server ID and client ID:
- From input (using the data passed from the trigger node)
- Custom (manually specify IDs)
- Use context server (automatically find active server)
- Set your response data (JSON or plain text)
- The node will send the response to the specified client(s)
Detailed Configuration
WebSocket Trigger Node Configuration
The WebSocket Trigger node has the following configuration options:
| Parameter | Type | Default | Description |
|---|---|---|---|
| Port | Number | 5680 | The port on which the WebSocket server will listen |
| Path | String | /ws | The URL path for the WebSocket endpoint |
| Connection ID | String | empty | Optional custom identifier for the server. If not provided, the port will be used |
When a WebSocket message is received, the node will trigger the workflow and provide the following output data:
{
"message": "Message content from client",
"serverId": "ws-5680",
"path": "/ws",
"port": 5680,
"clientId": "abc123",
"nodeId": "123456",
"executionId": "7890",
"contextInfo": {
"active": true
}
}
WebSocket Response Node Configuration
The WebSocket Response node has the following configuration options:
| Parameter | Type | Options | Default | Description |
|---|---|---|---|---|
| Connection ID Method | Dropdown | From Input, Custom, Use Context | From Input | How to determine which server to send the response to |
| Server ID Property | String | - | serverId | The property in the input data containing the server ID (when using "From Input") |
| Custom Server ID | String | - | empty | The server ID to use (when using "Custom") |
| Client ID Method | Dropdown | From Input, Custom, Broadcast | From Input | How to determine which client to send the response to |
| Client ID Property | String | - | clientId | The property in the input data containing the client ID (when using "From Input") |
| Custom Client ID | String | - | empty | The client ID to use (when using "Custom") |
| JSON Response | Boolean | - | true | Whether to format the response as JSON |
| Response Data | String | - | ={{ JSON.stringify($json) }} |
The response data to send (when JSON Response is false) |
| Response JSON | JSON | - | ={{ $json }} |
The JSON data to send (when JSON Response is true) |
Example Workflow Setup
Here's a complete example of how to set up a workflow with trigger and response:
Start with a WebSocket Trigger Node
- Set Port:
5680 - Set Path:
/ws - Leave Connection ID empty (will use port as identifier)
- Set Port:
Add processing nodes as needed
- You can manipulate the incoming data as required
- Make sure to preserve the
serverIdandclientIdfields if you need to respond
End with a WebSocket Response Node
- Connection ID Method:
From Input - Server ID Property:
serverId - Client ID Method:
From Input - Client ID Property:
clientId - Enable JSON Response
- Response JSON:
={{ {"result": "success", "message": "Processed your request", "data": $json.message} }}
- Connection ID Method:
This setup will ensure that responses are sent back to the same client that triggered the workflow.
Example Client Code (Browser)
// Connect to your configured WebSocket server
const ws = new WebSocket('ws://localhost:5680/ws');
// Send a message
ws.send(JSON.stringify({
message: 'Hello from client!'
}));
// Receive messages
ws.onmessage = (event) => {
console.log('Received:', event.data);
};
Example Client Code (Node.js)
const WebSocket = require('ws');
// Connect to your configured WebSocket server
const ws = new WebSocket('ws://localhost:5680/ws');
// Send a message when connection is established
ws.on('open', function open() {
ws.send(JSON.stringify({
message: 'Hello from Node.js client!'
}));
});
// Receive messages
ws.on('message', function message(data) {
console.log('Received:', data);
});
Troubleshooting
Connection Issues
If you're having trouble with WebSocket connections:
Check if the server is running
- Look for log messages like
[DEBUG-TRIGGER] WebSocket server created/retrieved successfully - Verify the port is not already in use by another service
- Look for log messages like
Connection is closing too quickly
- Check that you're using version 1.1.4 or later which implements the connection persistence
- Look for log messages like
[DEBUG-REGISTRY] Server soft-closed, connections maintained for ws-5680
Response not reaching clients
- Verify the client ID and server ID are correctly passed to the Response node
- Check that the client is still connected when the response is sent
- Look for log messages like
[DEBUG-RESPONSE] Message sent to client
Common Errors
| Error | Possible Cause | Solution |
|---|---|---|
WebSocket server with ID X not found |
Server was closed or never created | Check server configuration and workflow order |
Client with ID X not found |
Client disconnected before response was sent | Implement error handling or client reconnect logic |
Failed to send message after retries |
Network issues or client disconnected | Check network connectivity and client state |
Advantages Over Other WebSocket Nodes
- Standalone Operation: Works independently of n8n's HTTP server
- Customizable Endpoints: Configure port and path for each WebSocket server
- Connection Stability: Maintains connections between trigger and response nodes
- Keep-Alive Mechanism: Automatic ping/pong to prevent timeouts
- Execution Tracking: Prevents connections from closing during workflow testing
- Retry Logic: Reliable message delivery with automatic retries
Development
- Clone the repository
git clone https://github.com/subinsoman/n8n-nodes-websocket-standalone.git
- Install dependencies
npm install
- Build the package
npm run build
- Link to your n8n installation
npm link
cd /path/to/n8n
npm link n8n-nodes-websocket-standalone
License
Support
For issues and feature requests, please create an issue on GitHub.