{"library":"node-opcua-client","title":"OPC UA Client for Node.js","description":"node-opcua-client is the client-side module of a comprehensive OPC UA SDK written entirely in JavaScript and Node.js, providing robust connectivity to OPC UA servers. Currently at version 2.169.0, the library exhibits a rapid and consistent release cadence, often featuring multiple patch and minor releases per month to introduce new features, performance enhancements, and bug fixes. Key differentiators include its pure Node.js implementation, broad support for various OPC UA specifications (including OPC UA 1.05 compliance), and a strong emphasis on performance through optimizations in data type handling, transport, and secure channel operations. The project maintains an open-source MIT license but offers commercial support, advanced documentation, and value-added extensions through Sterfive SAS, catering to professional and industrial applications.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install node-opcua-client"],"cli":null},"imports":["import { OPCUAClient } from 'node-opcua-client';","import { ClientSession } from 'node-opcua-client';","import { MessageSecurityMode, SecurityPolicy, AttributeIds } from 'node-opcua-client';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import {\n    OPCUAClient,\n    MessageSecurityMode,\n    SecurityPolicy,\n    AttributeIds\n} from \"node-opcua-client\";\n\nasync function main() {\n    // Use process.env.OPCUA_SERVER_ENDPOINT_URL for flexibility, fallback to localhost\n    const endpointUrl = process.env.OPCUA_SERVER_ENDPOINT_URL ?? \"opc.tcp://localhost:4840\";\n    \n    // Create an OPC UA client instance\n    const client = OPCUAClient.create({\n        endpointUrl: endpointUrl,\n        securityMode: MessageSecurityMode.None, // No security for simplicity (dev/test)\n        securityPolicy: SecurityPolicy.None, // No security policy\n        connectionStrategy: {\n            maxRetry: 10,\n            initialDelay: 2000,\n            maxDelay: 10 * 1000\n        }\n    });\n\n    try {\n        // Connect the client to the OPC UA server\n        await client.connect(endpointUrl);\n        console.log(\"Client connected to endpoint:\", endpointUrl);\n\n        // Create a session with the server\n        const session = await client.createSession();\n        console.log(\"Session created with ID:\", session.sessionId.toString());\n\n        // Define the NodeId to read (e.g., Server_ServerStatus_CurrentTime)\n        const nodeIdToRead = \"ns=0;i=2258\"; \n        \n        // Read the value of the specified node\n        const dataValue = await session.read({\n            nodeId: nodeIdToRead,\n            attributeId: AttributeIds.Value\n        });\n        console.log(`Value of ${nodeIdToRead}: ${dataValue.value.value}`);\n\n        // Close the session and disconnect the client\n        await session.close();\n        console.log(\"Session closed.\");\n\n        await client.disconnect();\n        console.log(\"Client disconnected.\");\n\n    } catch (err) {\n        console.error(\"An error occurred during OPC UA operations:\", err);\n        process.exit(1);\n    }\n}\n\nmain();","lang":"typescript","description":"Demonstrates how to connect to an OPC UA server, create a session, and read a value from a well-known NodeId (Server_ServerStatus_CurrentTime).","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}