{"id":11441,"library":"node-opcua-server","title":"Node-OPCUA Server","description":"The `node-opcua-server` package provides a pure JavaScript and TypeScript implementation of an OPC UA (Open Platform Communications Unified Architecture) server stack, designed for Node.js environments. It facilitates secure and reliable data exchange in industrial automation, M2M, and IoT applications. The project is under active development, with frequent minor and patch releases, currently stable at version 2.169.0. Key differentiators include its complete native Node.js implementation, comprehensive support for OPC UA standards including full OPC UA 1.05 compliance (featuring subtyped structures, unions, and optimized data type handling), and a robust, typed event system. It ships with full TypeScript type definitions, enhancing developer experience. While the core server is open-source (MIT licensed), Sterfive SAS offers commercial support and value-added companion modules for advanced features like PubSub, web proxying, optimized clients, and Global Discovery Services.","status":"active","version":"2.169.0","language":"javascript","source_language":"en","source_url":"git://github.com/node-opcua/node-opcua","tags":["javascript","OPCUA","opcua","m2m","iot","opc ua","internet of things","typescript"],"install":[{"cmd":"npm install node-opcua-server","lang":"bash","label":"npm"},{"cmd":"yarn add node-opcua-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-opcua-server","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `OPCUAServer` class is generally imported from the umbrella `node-opcua` package, which re-exports server components, despite `node-opcua-server` being the specific module.","wrong":"import OPCUAServer from 'node-opcua-server';","symbol":"OPCUAServer","correct":"import { OPCUAServer } from 'node-opcua';"},{"note":"Common OPC UA data types are typically re-exported from the main `node-opcua` package for convenience. For specific enum values like `DataType.Boolean`, access via `DataType` import.","wrong":"import { DataType } from 'node-opcua-data-model';","symbol":"DataType","correct":"import { DataType } from 'node-opcua';"},{"note":"The `Variant` class, used for wrapping values with their data type, is commonly re-exported from the main `node-opcua` package.","wrong":"import { Variant } from 'node-opcua-data-value';","symbol":"Variant","correct":"import { Variant } from 'node-opcua';"},{"note":"Standard OPC UA status codes are re-exported from the main `node-opcua` package.","symbol":"StatusCodes","correct":"import { StatusCodes } from 'node-opcua';"},{"note":"The `NodeId` class, for uniquely identifying nodes in the address space, is commonly re-exported from the main `node-opcua` package.","symbol":"NodeId","correct":"import { NodeId } from 'node-opcua';"}],"quickstart":{"code":"import { OPCUAServer, DataType, Variant, StatusCodes, NodeId } from 'node-opcua';\n\nconst server = new OPCUAServer({\n    port: 4840, // default OPC UA port\n    resourcePath: '/UA/MyAwesomeServer',\n    buildInfo: {\n        productName: 'My Awesome OPCUA Server',\n        buildNumber: '7658',\n        buildDate: new Date(2026, 3, 19)\n    }\n});\n\nasync function startServer() {\n    await server.start();\n    console.log('Server started and listening on', server.endpoints[0].endpointUrl);\n    console.log('Press Ctrl+C to stop the server.');\n\n    server.on('post_initialize', () => {\n        // Define the address space\n        const addressSpace = server.engine.addressSpace;\n        if (!addressSpace) {\n            console.error('Address space not available.');\n            return;\n        }\n\n        const namespace = addressSpace.get = addressSpace.registerNamespace('http://mynamespace.com/UA/MyAwesomeServer/');\n        const device = namespace.addObject({\n            organizedBy: addressSpace.rootFolder.objects,\n            browseName: 'MyDevice'\n        });\n\n        let temperature = 25.0;\n        namespace.addVariable({\n            componentOf: device,\n            nodeId: 's=Temperature',\n            browseName: 'Temperature',\n            dataType: DataType.Double,\n            value: {\n                get: () => new Variant({\n                    dataType: DataType.Double,\n                    value: temperature\n                })\n            }\n        });\n\n        // Simulate temperature changes\n        setInterval(() => {\n            temperature = 20 + 10 * Math.sin(Date.now() / 10000); // Oscillation between 10 and 30\n        }, 1000);\n\n        console.log('Address space initialized with a Temperature variable.');\n    });\n\n    process.on('SIGINT', async () => {\n        console.log('Caught interrupt signal, shutting down server...');\n        await server.shutdown();\n        console.log('Server shut down.');\n        process.exit(0);\n    });\n}\n\nstartServer().catch(console.error);\n","lang":"typescript","description":"This quickstart code demonstrates how to create a basic OPC UA server, define a custom address space with a dynamic temperature variable, and handle graceful shutdown. It uses `node-opcua` for all core functionalities, including server instantiation, node creation, and data type handling."},"warnings":[{"fix":"Review your codebase for any direct or indirect reliance on `async` or `lodash` utilities that might have been supplied by older `node-opcua` versions. Ensure your application explicitly manages its own `async`/`lodash` dependencies if needed.","message":"Version 2.168.0 migrated core packages from `async` and `lodash` to native JavaScript patterns. While primarily internal, applications relying on implicit availability or specific behaviors of these dependencies within `node-opcua` might encounter unexpected issues or require adjustments.","severity":"breaking","affected_versions":">=2.168.0"},{"fix":"Consult the latest documentation for `OPCUACertificateManager` and server event handling. Update certificate provisioning logic to account for chain acceptance. Review event listeners, especially for security-related notifications like `channelSecured`.","message":"The certificate management architecture has undergone several overhauls (v2.164.2, v2.167.0, v2.168.0), including `TrustListClient.addCertificate` now accepting certificate chains and a new typed event system for post-handshake notifications. Existing code for certificate handling or event listeners might need updates.","severity":"breaking","affected_versions":">=2.164.2"},{"fix":"Ensure the `OPCUAServer` configuration includes `serverInfo.discoveryUrls` and `serverInfo.alternateEndpoints` with the externally accessible IP addresses or hostnames and ports. Set `endpointUrl` correctly if overriding.","message":"For deployments behind Docker, NAT, or reverse proxies, correctly configuring 'Advertised Endpoints' (introduced in v2.165.0) is crucial. Incorrect configuration will lead to clients being unable to connect or browse the server, as the server advertises incorrect connection details.","severity":"gotcha","affected_versions":">=2.165.0"},{"fix":"Perform comprehensive regression testing, especially for interactions with custom complex data types and large address spaces. Validate data serialization/deserialization if you're dealing with OPC UA 1.05 specific structures or unions.","message":"Major performance improvements and OPC UA 1.05 compliance updates, particularly for DataType handling (v2.163.0), might introduce subtle behavioral changes. Applications with complex information models or custom data types should be thoroughly tested.","severity":"gotcha","affected_versions":">=2.163.0"},{"fix":"Regularly update your Node.js runtime to the latest LTS version to ensure security and compatibility. Monitor `node-opcua` release notes for recommended Node.js versions.","message":"Security upgrades, such as the Node.js runtime update to 20.19.6 in v2.159.0, highlight the importance of keeping your Node.js environment updated. Using outdated Node.js versions can expose your application to known vulnerabilities.","severity":"breaking","affected_versions":">=2.159.0 (indirectly)"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the `port` in the `OPCUAServer` constructor to an available port, or stop the conflicting process. On Linux, use `sudo lsof -i :4840` to identify the process.","cause":"The configured OPC UA server port (default 4840) is already being used by another process on the system.","error":"Error: listen EADDRINUSE: address already in use :::4840"},{"fix":"Ensure the client's certificate is added to the server's trust list. Verify that the client and server are configured with compatible `securityMode` (e.g., `None`, `Sign`, `SignAndEncrypt`) and `securityPolicy` (e.g., `None`, `Basic256Sha256`). Regenerate certificates if they are expired or malformed.","cause":"The client's certificate is not trusted by the server, or there is a mismatch in security policies/modes, preventing a secure connection.","error":"Bad_SecurityChecksFailed (0x80030000)"},{"fix":"Run `npm install node-opcua` in your project directory. If using a monorepo or specific sub-packages, ensure all dependencies are correctly linked or installed.","cause":"The `node-opcua` package is not installed or not resolvable in the current project context.","error":"Error: Cannot find module 'node-opcua'"},{"fix":"Check server configuration for `port`, `resourcePath`, and especially `serverInfo.discoveryUrls` and `serverInfo.alternateEndpoints` if running behind NAT or Docker. Verify network connectivity and firewall settings. Ensure the server has started successfully without errors.","cause":"The server is not accessible at the specified endpoint, possibly due to firewall rules, incorrect IP/hostname, or misconfigured advertised endpoints (especially in Docker/NAT environments).","error":"Client unable to connect to opc.tcp://my-server-ip:4840/UA/MyAwesomeServer"}],"ecosystem":"npm"}