{"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-opcua-server"],"cli":null},"imports":["import { OPCUAServer } from 'node-opcua';","import { DataType } from 'node-opcua';","import { Variant } from 'node-opcua';","import { StatusCodes } from 'node-opcua';","import { NodeId } from 'node-opcua';"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}