{"library":"node-opcua-service-node-management","title":"node-opcua-service-node-management","description":"The `node-opcua-service-node-management` package is a core component of the pure Node.js OPC UA SDK, providing the essential structures and types for managing nodes within an OPC UA Address Space. As part of the actively developed `node-opcua` ecosystem (current stable version 2.169.0), it handles the OPC UA services for adding and deleting nodes programmatically. The library maintains a rapid release cadence, typically releasing new features and stability improvements every few weeks. Key differentiators include full OPC UA 1.05 compliance, significant performance optimizations in data type handling and transport layers, robust certificate management capabilities, and support for advanced deployment scenarios like advertised endpoints for Docker/NAT environments. This module specifically exposes the request and response message types for the Node Management Service Set, enabling developers to build OPC UA servers that can dynamically modify their address space.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-opcua-service-node-management"],"cli":null},"imports":["import { AddNodesItem } from 'node-opcua-service-node-management';","import { DeleteNodesItem } from 'node-opcua-service-node-management';","import { NodeClass } from 'node-opcua-nodeset-ua';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { OPCUAServer, Variant, DataType, NodeId, ReferenceTypeIds, QualifiedName } from 'node-opcua';\nimport { AddNodesItem, NodeClass } from 'node-opcua-service-node-management';\n\nasync function createServerAndAddNode() {\n  const server = new OPCUAServer({\n    port: 4334,\n    resourcePath: 'UA/MyNodeManagementServer',\n    buildInfo: {\n      productName: 'MyNodeManagementServer',\n      buildNumber: '7658',\n      buildDate: new Date()\n    }\n  });\n\n  await server.initialize();\n\n  const addressSpace = server.engine.addressSpace;\n  if (!addressSpace) {\n    throw new Error('AddressSpace not initialized');\n  }\n\n  // Add a custom namespace\n  const namespace = addressSpace.registerNamespace('http://mynamespace.com/UA/Demo/');\n  console.log('Registered Namespace Index:', namespace.index);\n\n  // Add a new folder node programmatically using AddNodesItem\n  const folderBrowseName = new QualifiedName({ name: 'MyDynamicFolder', namespaceIndex: namespace.index });\n  const folderNodeId = new NodeId('s=MyDynamicFolder', namespace.index);\n\n  const addFolderItem: AddNodesItem = new AddNodesItem({\n    parentNodeId: addressSpace.getFolderId('Objects') || new NodeId('i=85'), // Objects folder\n    referenceTypeId: ReferenceTypeIds.Organizes,\n    requestedNewNodeId: folderNodeId,\n    browseName: folderBrowseName,\n    nodeClass: NodeClass.Object,\n    nodeAttributes: {\n      displayName: { text: 'My Dynamic Folder' },\n      description: { text: 'A folder created dynamically' }\n    }\n  });\n\n  // In a real application, you would invoke the AddNodes service with these items.\n  // For a server adding nodes to its own address space, direct `addressSpace.addNode` is often used,\n  // but this demonstrates the structure of AddNodesItem.\n  // For simplicity, we'll demonstrate what the internal `addNode` might receive, or how a client would send it.\n\n  const newFolder = addressSpace.addFolder(addFolderItem.parentNodeId, addFolderItem.browseName.name);\n  newFolder.setNodeId(addFolderItem.requestedNewNodeId);\n  console.log(`Dynamically added folder: ${newFolder.browseName.toString()} (NodeId: ${newFolder.nodeId.toString()})`);\n\n  await server.start();\n  console.log(`Server is now listening on ${server.endpoints[0].endpointUrl}`);\n  console.log('Press Ctrl+C to stop the server.');\n\n  process.on('SIGINT', async () => {\n    await server.shutdown();\n    console.log('Server shut down.');\n    process.exit(0);\n  });\n}\n\ncreateServerAndAddNode().catch(console.error);\n","lang":"typescript","description":"This quickstart demonstrates how to initialize an OPC UA server and use `AddNodesItem` to define and add a new folder node to its address space dynamically. It illustrates the structure for client-initiated node creation requests.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}