0
# Network Nodes
1
2
Network nodes provide comprehensive communication capabilities supporting HTTP servers and clients, MQTT messaging, WebSocket connections, and TCP/UDP protocols. These nodes enable Node-RED flows to interact with web services, IoT devices, and network-based systems.
3
4
## Capabilities
5
6
### HTTP Server Nodes
7
8
Create HTTP server endpoints that can receive requests and send responses.
9
10
```javascript { .api }
11
/**
12
* HTTP In node - creates HTTP server endpoints
13
* Registers as node type: "http in"
14
*/
15
function HTTPInNode(config) {
16
RED.nodes.createNode(this, config);
17
18
// Configuration properties:
19
// config.url - URL path pattern (e.g., "/api/data/:id")
20
// config.method - HTTP method: "get", "post", "put", "patch", "delete"
21
// config.upload - Handle file uploads
22
// config.swaggerDoc - Swagger documentation
23
}
24
25
/**
26
* HTTP Response node - sends HTTP responses
27
* Registers as node type: "http response"
28
*/
29
function HTTPResponseNode(config) {
30
RED.nodes.createNode(this, config);
31
32
// Configuration properties:
33
// config.statusCode - HTTP status code
34
// config.headers - Response headers object
35
}
36
```
37
38
**Usage Examples:**
39
40
```javascript
41
// REST API endpoint
42
{
43
"id": "http-in-1",
44
"type": "http in",
45
"url": "/api/users/:id",
46
"method": "get"
47
}
48
49
// POST endpoint with file upload
50
{
51
"type": "http in",
52
"url": "/upload",
53
"method": "post",
54
"upload": true
55
}
56
57
// HTTP response configuration
58
{
59
"type": "http response",
60
"statusCode": "200",
61
"headers": {
62
"Content-Type": "application/json",
63
"Access-Control-Allow-Origin": "*"
64
}
65
}
66
```
67
68
### HTTP Client Node
69
70
Make HTTP requests to external services with full configuration options.
71
72
```javascript { .api }
73
/**
74
* HTTP Request node - makes HTTP client requests
75
* Registers as node type: "http request"
76
*/
77
function HTTPRequestNode(config) {
78
RED.nodes.createNode(this, config);
79
80
// Configuration properties:
81
// config.method - HTTP method: "GET", "POST", "PUT", "DELETE", etc.
82
// config.ret - Return type: "txt", "bin", "obj"
83
// config.paytoqs - Send payload as query string
84
// config.url - Target URL
85
// config.tls - TLS configuration node ID
86
// config.proxy - HTTP proxy configuration node ID
87
// config.authType - Authentication type: "basic", "digest", "bearer"
88
// config.senderr - Send error responses
89
}
90
```
91
92
**Usage Examples:**
93
94
```javascript
95
// GET request
96
{
97
"method": "GET",
98
"url": "https://api.example.com/data",
99
"ret": "obj"
100
}
101
102
// POST with authentication
103
{
104
"method": "POST",
105
"url": "https://api.example.com/users",
106
"authType": "bearer",
107
"ret": "obj"
108
}
109
```
110
111
### MQTT Nodes
112
113
MQTT messaging support for IoT and event-driven communication.
114
115
```javascript { .api }
116
/**
117
* MQTT In node - subscribes to MQTT topics
118
* Registers as node type: "mqtt in"
119
*/
120
function MqttInNode(config) {
121
RED.nodes.createNode(this, config);
122
123
// Configuration properties:
124
// config.topic - MQTT topic to subscribe to
125
// config.qos - Quality of Service level (0, 1, 2)
126
// config.datatype - Data type: "auto", "buffer", "utf8", "json"
127
// config.broker - MQTT broker configuration node ID
128
}
129
130
/**
131
* MQTT Out node - publishes to MQTT topics
132
* Registers as node type: "mqtt out"
133
*/
134
function MqttOutNode(config) {
135
RED.nodes.createNode(this, config);
136
137
// Configuration properties:
138
// config.topic - MQTT topic to publish to
139
// config.qos - Quality of Service level
140
// config.retain - Retain message flag
141
// config.broker - MQTT broker configuration node ID
142
}
143
144
/**
145
* MQTT Broker configuration node
146
* Registers as node type: "mqtt-broker"
147
*/
148
function MqttBrokerNode(config) {
149
RED.nodes.createNode(this, config);
150
151
// Configuration properties:
152
// config.broker - Broker hostname/IP
153
// config.port - Broker port (default 1883)
154
// config.tls - TLS configuration node ID
155
// config.clientid - MQTT client ID
156
// config.keepalive - Keep alive interval
157
// config.cleansession - Clean session flag
158
// config.username - Authentication username
159
// config.password - Authentication password
160
}
161
```
162
163
**Usage Examples:**
164
165
```javascript
166
// MQTT broker configuration
167
{
168
"type": "mqtt-broker",
169
"broker": "mqtt.example.com",
170
"port": "1883",
171
"clientid": "node-red-client",
172
"keepalive": "60",
173
"cleansession": true
174
}
175
176
// MQTT subscriber
177
{
178
"type": "mqtt in",
179
"topic": "sensors/temperature/+",
180
"qos": "1",
181
"datatype": "json",
182
"broker": "broker-id"
183
}
184
185
// MQTT publisher
186
{
187
"type": "mqtt out",
188
"topic": "actuators/relay1",
189
"qos": "0",
190
"retain": false,
191
"broker": "broker-id"
192
}
193
```
194
195
### WebSocket Nodes
196
197
WebSocket communication for real-time bidirectional messaging.
198
199
```javascript { .api }
200
/**
201
* WebSocket In node - receives WebSocket messages
202
* Registers as node type: "websocket in"
203
*/
204
function WebSocketInNode(config) {
205
RED.nodes.createNode(this, config);
206
207
// Configuration properties:
208
// config.path - WebSocket path (for server mode)
209
// config.wholemsg - Send whole message or just payload
210
// config.client - WebSocket client configuration node ID
211
}
212
213
/**
214
* WebSocket Out node - sends WebSocket messages
215
* Registers as node type: "websocket out"
216
*/
217
function WebSocketOutNode(config) {
218
RED.nodes.createNode(this, config);
219
220
// Configuration properties:
221
// config.path - WebSocket path
222
// config.client - WebSocket client configuration node ID
223
}
224
225
/**
226
* WebSocket Listener configuration node - WebSocket server configuration
227
* Registers as node type: "websocket-listener"
228
*/
229
function WebSocketListenerNode(config) {
230
RED.nodes.createNode(this, config);
231
232
// Configuration properties:
233
// config.path - WebSocket server path
234
// config.wholemsg - Send whole message or just payload
235
}
236
237
/**
238
* WebSocket Client configuration node - WebSocket client connection settings
239
* Registers as node type: "websocket-client"
240
*/
241
function WebSocketClientNode(config) {
242
RED.nodes.createNode(this, config);
243
244
// Configuration properties:
245
// config.path - WebSocket server URL
246
// config.wholemsg - Send whole message or just payload
247
// config.subprotocol - WebSocket subprotocol
248
// config.hb - Heartbeat interval
249
// config.proxy - HTTP proxy configuration
250
}
251
```
252
253
### TCP Nodes
254
255
TCP client and server functionality for direct socket communication.
256
257
```javascript { .api }
258
/**
259
* TCP In node - TCP server or client receiver
260
* Registers as node type: "tcp in"
261
*/
262
function TcpInNode(config) {
263
RED.nodes.createNode(this, config);
264
265
// Configuration properties:
266
// config.port - Port number (for server mode)
267
// config.host - Host address (for client mode)
268
// config.datamode - Data mode: "stream", "single"
269
// config.newline - Line separator character
270
// config.topic - Message topic
271
// config.trim - Trim whitespace
272
// config.base64 - Base64 decode incoming data
273
}
274
275
/**
276
* TCP Out node - TCP client sender
277
* Registers as node type: "tcp out"
278
*/
279
function TcpOutNode(config) {
280
RED.nodes.createNode(this, config);
281
282
// Configuration properties:
283
// config.host - Target host
284
// config.port - Target port
285
// config.beserver - Act as server
286
// config.base64 - Base64 encode outgoing data
287
// config.end - Close connection after send
288
}
289
290
/**
291
* TCP Request node - TCP request/response client
292
* Registers as node type: "tcp request"
293
*/
294
function TcpRequestNode(config) {
295
RED.nodes.createNode(this, config);
296
297
// Configuration properties:
298
// config.server - Target server
299
// config.port - Target port
300
// config.out - Output type: "time", "char", "count"
301
// config.splitc - Split character
302
// config.timeout - Request timeout
303
}
304
```
305
306
### UDP Nodes
307
308
UDP communication for connectionless messaging.
309
310
```javascript { .api }
311
/**
312
* UDP In node - receives UDP messages
313
* Registers as node type: "udp in"
314
*/
315
function UdpInNode(config) {
316
RED.nodes.createNode(this, config);
317
318
// Configuration properties:
319
// config.port - UDP port to listen on
320
// config.bind - Bind address
321
// config.multicast - Multicast group address
322
// config.group - Multicast group
323
// config.datatype - Data type: "utf8", "buffer"
324
// config.iface - Network interface
325
}
326
327
/**
328
* UDP Out node - sends UDP messages
329
* Registers as node type: "udp out"
330
*/
331
function UdpOutNode(config) {
332
RED.nodes.createNode(this, config);
333
334
// Configuration properties:
335
// config.addr - Target address
336
// config.port - Target port
337
// config.iface - Network interface
338
// config.multicast - Multicast mode
339
// config.outport - Source port
340
}
341
342
// HTTP endpoint for UDP port information
343
// GET /udp-ports/:id - Get UDP port details for node
344
```
345
346
**Usage Examples:**
347
348
```javascript
349
// UDP listener
350
{
351
"type": "udp in",
352
"port": "1234",
353
"bind": "0.0.0.0",
354
"datatype": "utf8"
355
}
356
357
// UDP sender
358
{
359
"type": "udp out",
360
"addr": "192.168.1.100",
361
"port": "5678"
362
}
363
364
// UDP multicast receiver
365
{
366
"type": "udp in",
367
"port": "1234",
368
"multicast": "true",
369
"group": "224.0.0.1"
370
}
371
```
372
373
## Configuration Nodes
374
375
Network nodes use configuration nodes for shared settings.
376
377
### TLS Configuration
378
379
```javascript { .api }
380
/**
381
* TLS Config node - SSL/TLS certificate configuration
382
* Registers as node type: "tls-config"
383
*/
384
function TLSConfigNode(config) {
385
RED.nodes.createNode(this, config);
386
387
// Configuration properties:
388
// config.cert - Client certificate
389
// config.key - Private key
390
// config.ca - Certificate Authority
391
// config.certname - Certificate file name
392
// config.keyname - Key file name
393
// config.caname - CA file name
394
// config.servername - Server name for SNI
395
// config.verifyservercert - Verify server certificate
396
}
397
```
398
399
### HTTP Proxy Configuration
400
401
```javascript { .api }
402
/**
403
* HTTP Proxy node - proxy configuration for HTTP requests
404
* Registers as node type: "http proxy"
405
*/
406
function HttpProxyNode(config) {
407
RED.nodes.createNode(this, config);
408
409
// Configuration properties:
410
// config.url - Proxy URL
411
// config.username - Proxy username
412
// config.password - Proxy password
413
}
414
```
415
416
## Message Patterns
417
418
Network nodes handle various message patterns:
419
420
```javascript { .api }
421
// HTTP In message structure
422
interface HttpInMessage {
423
payload: any; // Request body
424
req: { // HTTP request object
425
params: object; // URL parameters
426
query: object; // Query parameters
427
headers: object; // Request headers
428
method: string; // HTTP method
429
url: string; // Request URL
430
cookies: object; // Request cookies
431
};
432
res: object; // HTTP response object (for response node)
433
}
434
435
// MQTT message structure
436
interface MqttMessage {
437
payload: any; // Message payload
438
topic: string; // MQTT topic
439
qos: number; // Quality of Service
440
retain: boolean; // Retain flag
441
}
442
443
// TCP/UDP message structure
444
interface NetworkMessage {
445
payload: any; // Message data
446
ip: string; // Source/destination IP
447
port: number; // Source/destination port
448
}
449
```
450
451
## Authentication Support
452
453
HTTP nodes support various authentication methods:
454
455
```javascript { .api }
456
// Basic authentication
457
{
458
"authType": "basic",
459
"user": "username",
460
"password": "password"
461
}
462
463
// Bearer token authentication
464
{
465
"authType": "bearer",
466
"token": "access_token"
467
}
468
469
// Digest authentication
470
{
471
"authType": "digest",
472
"user": "username",
473
"password": "password"
474
}
475
```