Skip to main content

A structured namespace layout

Goal

Organize your address space in a clean, scalable layout using folders and objects.

Example layout

This example creates a Devices folder and adds two device objects with variables.

// Create a top-level folder
const devicesFolder = namespace.addFolder("ObjectsFolder", { browseName: "Devices" });

// Create two devices under the folder
const deviceA = namespace.addObject({
organizedBy: devicesFolder,
browseName: "DeviceA"
});

const deviceB = namespace.addObject({
organizedBy: devicesFolder,
browseName: "DeviceB"
});

// Add variables to DeviceA
const status = namespace.addVariable({
componentOf: deviceA,
browseName: "Status",
dataType: "String"
});

const speed = namespace.addVariable({
componentOf: deviceA,
browseName: "Speed",
dataType: "Double"
});

// Set initial values (and update later with new messages)
status.setValueFromSource({ dataType: opcua.DataType.String, value: "Running" });
speed.setValueFromSource({ dataType: opcua.DataType.Double, value: msg.speed || 0 });

Tips

  • Use folders for grouping (e.g., Devices, Lines, Areas).
  • Use consistent naming to make clients easier to browse.
  • Keep your NodeIds stable to avoid breaking clients.

Further reading

For more tips and examples, see the Sterfive book node-opcua by example.