Node.js / TypeScript · recipe

Browse an OPC UA address space in Node.js

Call browse on a node and read the references it returns. Each reference carries the browse name, node class and type definition, which is enough to tell a typed machine object from a folder of tags without a second round trip.

Stacknode-opcua
Version2.181.1

The code

const { OPCUAClient, BrowseDirection, NodeClassMask, ResultMask } = require("node-opcua");

(async () => {
  const client = OPCUAClient.create({ endpointMustExist: false });
  await client.connect("opc.tcp://opcua.umati.app:4840");
  const session = await client.createSession();

  const result = await session.browse({
    nodeId: "ObjectsFolder",
    browseDirection: BrowseDirection.Forward,
    referenceTypeId: "HierarchicalReferences",
    includeSubtypes: true,
    nodeClassMask: NodeClassMask.Object | NodeClassMask.Variable,
    resultMask: ResultMask.BrowseName | ResultMask.NodeClass | ResultMask.TypeDefinition,
  });

  for (const ref of result.references) {
    console.log(ref.browseName.toString().padEnd(24),
                ref.nodeClass.toString().padEnd(10),
                ref.nodeId.toString());
  }

  await session.close();
  await client.disconnect();
})();

What it prints

Server                   Object     ns=0;i=85
Machines                 Object     ns=3;i=1001
DeviceSet                Object     ns=2;i=5001

Notes

  • Filter with nodeClassMask and referenceTypeId in the request. Pulling every reference and filtering in JavaScript wastes a round trip and the server's continuation points.
  • Request TypeDefinition in the resultMask. Seeing MachineToolType come back tells you immediately that this is a semantic integration rather than tag-scraping.
  • If `result.continuationPoint` is set there is more to fetch: call browseNext, and release continuation points you abandon.
  • `opcua-commander` gives you an interactive tree over SSH with no code, which is often what you actually want on a gateway.

What breaks first

A browse of a large address space exhausts the server's continuation points BadNoContinuationPoints
Servers cap concurrent continuation points. Consume or release each one before starting another browse, and filter harder so there are fewer.

Last verified 7 September 2026 against OPC UA 1.05.07. OPC UA Connect is an educational resource and is not affiliated with the OPC Foundation.

Free download
OPC UA Troubleshooting & Integration Checklist
The field-tested checklist engineers use to diagnose certificates, ports and namespace problems fast, plus a Python (asyncua) client template.
Get the free checklist →
Free, no course, no login