NodeOPCUA is the most complete OPC UA stack for Node.js — build industrial-grade OPC UA servers and clients in TypeScript.
import { OPCUAClient, AttributeIds, DataType } from "node-opcua";
const client = OPCUAClient.create({ endpointMustExist: false });
await client.connect("opc.tcp://localhost:26543");
const session = await client.createSession();
// Read the server's current time
const dataValue = await session.read({
nodeId: "ns=0;i=2258",
attributeId: AttributeIds.Value,
});
console.log("Server time:", dataValue.value.value);
await session.close();
await client.disconnect();
| Concept | Description |
|---|---|
| OPCUAClient | Connect to OPC UA servers, create sessions, and subscribe to data |
| OPCUAServer | Create OPC UA servers with custom address spaces |
| AddressSpace | The server's information model — add variables, objects, and methods |
| ClientSession | Read, write, browse, call methods, and manage subscriptions |
| NodeId | Unique identifier for every node in an OPC UA address space |
| Variant | Container for typed OPC UA values |
| DataValue | Value + status code + timestamps |