{"library":"node-opcua-service-register-node","title":"node-opcua Service Register Node","description":"The `node-opcua-service-register-node` package is a module within the comprehensive `node-opcua` SDK, a pure Node.js and TypeScript implementation of the OPC UA specification. The SDK is designed for building high-performing asynchronous applications, leveraging Node.js's capabilities. It adheres to a 'Perpetual Beta' model, with new enhanced versions released approximately every two weeks, ensuring continuous improvement and community testing. The project emphasizes quality with over 3500 unit tests and 93% code coverage. This specific module primarily defines the data structures and message types for the OPC UA RegisterNodes Service, which allows OPC UA clients to register NodeIds with a server for more efficient, repeated access operations. The current stable version of the `node-opcua` ecosystem is 2.169.0.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install node-opcua-service-register-node"],"cli":null},"imports":["import { RegisterNodesRequest } from 'node-opcua-service-register-node';","import { RegisterNodesResponse } from 'node-opcua-service-register-node';","import { NodeId } from 'node-opcua';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { OPCUAServer, OPCUAClient, MessageSecurityMode, SecurityPolicy, UserTokenType, NodeId, resolveNodeId } from 'node-opcua';\nimport { RegisterNodesRequest, RegisterNodesResponse } from 'node-opcua-service-register-node';\n\nasync function startOpcUaExample() {\n  // 1. Setup a simple OPC UA Server\n  const server = new OPCUAServer({\n    port: 4334,\n    resourcePath: '/UA/MyServer',\n    buildInfo: {\n      productName: 'MySampleServer',\n      buildNumber: '1234',\n      buildDate: new Date()\n    }\n  });\n\n  await server.initialize();\n  const addressSpace = server.engine.addressSpace;\n  if (!addressSpace) { throw new Error('AddressSpace not initialized'); }\n\n  const device = addressSpace.getFolder('ObjectsFolder')?.addFolder({\n    browseName: 'MyDevice'\n  });\n\n  if (device) {\n    device.addVariable({\n      browseName: 'Temperature',\n      nodeId: 's=TemperatureSensor1',\n      dataType: 'Double',\n      value: { get: () => new Variant({ dataType: DataType.Double, value: 25.5 }) }\n    });\n    console.log('Server initialized with a Temperature variable.');\n  }\n  \n  await server.start();\n  console.log(`Server is running at ${server.endpoints[0]?.endpointDescriptions()[0]?.endpointUrl}`);\n\n  // 2. Setup a simple OPC UA Client and demonstrate RegisterNodesRequest structure\n  const client = OPCUAClient.create({\n    endpointUrl: server.endpoints[0]?.endpointDescriptions()[0]?.endpointUrl,\n    securityMode: MessageSecurityMode.None,\n    securityPolicy: SecurityPolicy.None,\n    connectionStrategy: { maxRetry: 0 }\n  });\n\n  try {\n    await client.connect(server.endpoints[0]?.endpointDescriptions()[0]?.endpointUrl ?? '');\n    console.log('Client connected to server.');\n\n    const session = await client.createSession({\n      userIdentity: { type: UserTokenType.Anonymous }\n    });\n    console.log('Client session created.');\n\n    // Create a RegisterNodesRequest (this package provides the type definition)\n    const nodesToRegister = [\n      resolveNodeId('s=TemperatureSensor1'),\n      new NodeId('ns=1;s=AnotherNode') // Example of another node\n    ];\n    \n    const registerRequest = new RegisterNodesRequest({\n      nodesToRegister: nodesToRegister\n    });\n\n    console.log('Constructed RegisterNodesRequest:', JSON.stringify(registerRequest.toJSON(), null, 2));\n    \n    // In a real client, you would send this request via session.performMessage or similar:\n    // const response: RegisterNodesResponse = await session.registerNodes(registerRequest.nodesToRegister);\n    // console.log('RegisterNodes response:', response);\n\n    await session.close();\n    await client.disconnect();\n    console.log('Client disconnected.');\n\n  } catch (err) {\n    console.error('Client error:', err);\n  } finally {\n    await server.shutdown();\n    console.log('Server shut down.');\n  }\n}\n\nstartOpcUaExample().catch(console.error);\n","lang":"typescript","description":"This quickstart demonstrates how to set up a minimal `node-opcua` server and client, and then shows how to construct a `RegisterNodesRequest` object using types provided by this package for registering NodeIds with the server to optimize subsequent access.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}