Node-OPCUA Standard NodeSets

2.169.0 · active · verified Wed Apr 22

The `node-opcua-nodeset-ua` package is a core component of the `node-opcua` SDK, providing the standard OPC UA NodeSet XML definitions. These definitions are essential for building OPC UA servers that expose a semantically rich address space conforming to the OPC UA Unified Architecture specification. As part of the highly active `node-opcua` monorepo, it receives frequent updates, typically bi-weekly, aligning with the project's 'Perpetual Beta' model. The current stable version is 2.169.0. Key differentiators for the `node-opcua` ecosystem, including this module, include its pure Node.js implementation, extensive TypeScript support, and a focus on industrial IoT (IIoT) and Machine-to-Machine (M2M) communication. It allows developers to load standard and custom information models into an OPC UA server's address space for robust data exposure.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to set up a basic OPC UA server and load the standard NodeSet 2.0 information model using `node-opcua-nodeset-ua` to establish a foundational address space.

import { OPCUAServer } from 'node-opcua-server';
import { standardNodeSet2 } from 'node-opcua-nodeset-ua';

async function main() {
  // Create an OPC UA Server instance
  const server = new OPCUAServer({
    port: 4840, // Default OPC UA port
    resourcePath: '/UA/MyNodeSetServer',
    buildInfo: {
      productName: 'NodeSet Example Server',
      buildNumber: '1',
      buildDate: new Date(),
    },
  });

  // Initialize the server
  await server.initialize();
  console.log('Server initialized.');

  // Load the standard OPC UA NodeSet (version 2) into the server's address space
  // The `standardNodeSet2` export provides the XML content as a string.
  await server.loadUAModel({
    nodeset_filename: [standardNodeSet2], // Pass the NodeSet XML string here
  });
  console.log('Standard NodeSet2 loaded.');

  // Optionally, extend the address space with custom objects or variables
  const addressSpace = server.engine.addressSpace;
  if (addressSpace) {
    const objectsFolder = addressSpace.getFolder('ObjectsFolder');
    const myDeviceFolder = objectsFolder?.addFolder({
      browseName: 'MyCustomDevices',
      displayName: 'My Custom Devices',
    });
    myDeviceFolder?.addVariable({
      browseName: 'Temperature',
      dataType: 'Double',
      value: { get: () => new server.variant({ dataType: server.DataType.Double, value: 25.5 }) },
    });
  }
  console.log('Custom objects added to address space.');

  // Start the server
  await server.start();
  console.log(`Server is now listening on port ${server.port}`);
  console.log(`Server discovery URL: ${server.getEndpointUrl()}`);
  console.log('Press Ctrl+C to stop the server.');

  // Handle server shutdown on SIGINT
  process.on('SIGINT', async () => {
    console.log('Shutting down server...');
    await server.shutdown();
    console.log('Server shut down.');
    process.exit(0);
  });
}

main().catch(console.error);

view raw JSON →