Registry / http-networking / node-opcua-server-discovery

node-opcua-server-discovery

JSON →
library2.169.0jsnpmunverified

This module, `node-opcua-server-discovery`, is a core component of the `node-opcua` SDK, a pure Node.js implementation of the OPC UA specification. It provides the functionality for OPC UA servers to register themselves with a Local Discovery Server (LDS) or for clients to discover available OPC UA servers on a network. The package is currently at version 2.169.0 and maintains a highly active release cadence, often publishing updates multiple times a month, focusing on stability, performance, OPC UA 1.05 compliance, and enhanced security features like certificate management. Its key differentiators include being a complete, native JavaScript/TypeScript implementation, offering strong support for modern Node.js environments, and a consistent focus on optimizing transport, memory, and protocol robustness.

npm install node-opcua-server-discovery
INSTALL
IMPORT
SIG · NODE-OPCUA-SERVER-
N
node-opcua-server-discovery
http-networkingjavascriptv2.169.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OPCUADiscoveryServer
import { OPCUADiscoveryServer } from 'node-opcua-server-discovery';
const OPCUADiscoveryServer = require('node-opcua-server-discovery');
The `node-opcua` ecosystem primarily uses ES Modules and TypeScript. While CommonJS might work in some older Node.js contexts, ESM is the recommended and best-supported import method.
DiscoveryServerOptions
import type { DiscoveryServerOptions } from 'node-opcua-server-discovery';
Import types separately using `import type` for clarity and to ensure type-only imports are correctly handled by TypeScript compilers and bundlers.
CertificateManager
import { CertificateManager } from 'node-opcua-pki';
While not directly from `server-discovery`, certificate management is crucial for OPC UA security. `node-opcua-pki` is a closely related and often required dependency for configuring secure discovery services.

This code snippet demonstrates how to initialize and start an OPC UA Local Discovery Server (LDS) using `node-opcua-server-discovery`. It includes essential steps for certificate management, defining server information, and graceful shutdown. This LDS can then be used by other OPC UA servers to register themselves, and by clients to discover available services.

import { OPCUADiscoveryServer } from 'node-opcua-server-discovery'; import { CertificateManager } from 'node-opcua-pki'; import path from 'path'; import os from 'os'; async function startDiscoveryServer() { const pkiFolder = path.join(os.tmpdir(), "pki_for_discovery"); const certificateManager = new CertificateManager({ pki: pkiFolder }); await certificateManager.initialize(); // Ensure a self-signed certificate is available for the discovery server await certificateManager.createSelfSignedCertificate({ applicationUri: 'urn:MyNodeOPCUADiscoveryServer', applicationName: { text: 'My Node-OPCUA Discovery Server', locale: 'en-US' }, dns: [os.hostname(), 'localhost'], ip: [], // Add your server's IP if necessary startDate: new Date(), endDate: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000) // 1 year validity }); const discoveryServer = new OPCUADiscoveryServer({ port: 4840, serverInfo: { applicationUri: 'urn:MyNodeOPCUADiscoveryServer', applicationName: { text: 'My Node-OPCUA Discovery Server', locale: 'en-US' }, productUri: 'https://github.com/node-opcua/node-opcua', }, certificateManager: certificateManager, // Optional: Specify server endpoints for the discovery server itself // For example, if running behind NAT/Docker with advertised endpoints // advertisedEndpoints: ['opc.tcp://my-public-host:4840'] }); await discoveryServer.start(); console.log(`OPC UA Discovery Server started on port ${discoveryServer.port}.`); console.log(`PKI folder: ${pkiFolder}`); process.on('SIGINT', async () => { console.log('Stopping discovery server...'); await discoveryServer.shutdown(); console.log('Discovery server stopped.'); process.exit(0); }); } startDiscoveryServer().catch(err => { console.error('Failed to start discovery server:', err); process.exit(1); });
Debug
Known issues
breakingVersion `2.168.0` significantly refactored core packages, migrating from `async` and `lodash` to native modern JavaScript patterns. While primarily internal, changes to the 'more robust typed event system' may introduce breaking changes to existing event listeners or custom extensions relying on previous internal event structures.
fix
Review and update any custom event handlers or modules that might be interacting with the internal event system or relying on `async`/`lodash` utilities directly. Consult `node-opcua`'s main documentation for updated event patterns.
affects: >=2.168.0
gotchaBeginning with `v2.165.0`, `node-opcua` introduced enhanced 'Advertised Endpoints' support for Docker, NAT, or proxy deployments. Incorrectly configuring advertised endpoints can lead to discovery failures where clients cannot connect to the server's actual network location.
fix
For servers running behind network address translation (NAT), Docker port-mapping, or reverse proxies, ensure the `advertisedEndpoints` option is correctly configured with the publicly accessible endpoint URLs. Validate these URLs from the client's perspective.
affects: >=2.165.0
gotchaChanges in OPC UA 1.05 compliance and DataType handling (v2.163.0) can impact applications dealing with complex or custom information models. While providing performance improvements, previous non-compliant type handling might now be stricter.
fix
If your application uses custom OPC UA DataTypes or relies on specific encoding/decoding behaviors, thoroughly test against `v2.163.0` and later versions. Ensure your information models strictly adhere to OPC UA 1.05 specifications. Re-evaluate any custom extension object or variant handling.
affects: >=2.163.0
gotchaThe `node-opcua` ecosystem relies heavily on X.509 certificates for secure communication. Misconfiguration or missing certificates (e.g., self-signed certificates for the discovery server itself, or trusted certificates for registering servers) are common sources of connection errors.
fix
Always ensure your `OPCUADiscoveryServer` instance has a valid `CertificateManager` configured with appropriate certificates. For client-server communication via discovery, ensure that both the discovery server and the registered OPC UA servers have trusted certificates configured on both sides.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Certificate validation failed for endpoint 'opc.tcp://localhost:4840'
The client (or discovery server) does not trust the server's (or discovery server's) certificate, or the certificate's application URI/DNS name does not match the endpoint URL.
fix
Ensure the server's certificate is in the client's trusted certificates store, and vice versa. Verify that the `applicationUri` in the certificate matches the server's configured URI and that DNS names/IPs in the certificate match the endpoint URL used for connection. Regenerate certificates if necessary, ensuring proper hostnames/IPs.
Error: read ECONNRESET
This typically indicates a network connectivity issue or a premature termination of the connection, often due to firewalls, incorrect endpoint URLs, or server-side certificate validation failures leading to an immediate disconnect.
fix
Check network connectivity between client and server, including firewall rules on both ends (port 4840 for LDS, default 4840 or custom for OPC UA servers). Verify the endpoint URL is correct and accessible. Review server logs for errors related to connection establishment or certificate rejection.
TypeError: Cannot read properties of undefined (reading 'start')
The `OPCUADiscoveryServer` instance was not properly initialized before attempting to call its `start()` method, likely due to missing or incorrect constructor arguments.
fix
Ensure the `OPCUADiscoveryServer` constructor is called with all required options, including `port`, `serverInfo`, and `certificateManager`. Double-check the types and availability of these properties before passing them to the constructor.
Upgrade
Version history
2.169.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources