The whole protocol
RFC 6241 and 6242 over SSH or TLS, with both framings, pipelining, confirmed commits, call home, and typed rpc-errors. Three runtime dependencies, one of them its sibling @node-net/yang.
A modern, RFC-compliant NETCONF client in TypeScript. Read and write any YANG model by path, and describe each device's differences in a JSON file instead of code.
npm install @node-net/netconfimport { connect, ssh, knownHostsFile } from '@node-net/netconf';
await using client = await connect({
transport: ssh({
host: 'router1.example.net',
username: 'admin',
password: () => process.env.ROUTER_PASSWORD!,
hostKey: knownHostsFile(),
}),
});
const IF = '/ietf-interfaces:interfaces/interface[name="eth0"]';
// <get-config> from running, filtered to the path
console.log(await client.content.readValue(`${IF}/description`));
// <lock>, <edit-config>, <validate>, <commit>, <unlock>,
// as the device's workflow says
await client.content.set(`${IF}/description`, 'uplink');import { subtree, withCandidate, x } from '@node-net/netconf';
// client: connected as in "By path"
const IF = 'urn:ietf:params:xml:ns:yang:ietf-interfaces';
// <get-config> with a subtree filter
const data = await client.ops.getConfig({
filter: subtree(
x('interfaces', { xmlns: IF }, x('interface', x('name', 'eth0'))),
),
});
console.log(data.path('interfaces/interface/description')?.text());
// <lock>s, <edit-config>, <validate>, <commit>, <unlock>s,
// discarding on failure
await withCandidate(client, (txn) => txn.editConfig({
config: x('interfaces', { xmlns: IF },
x('interface', x('name', 'eth0'), x('description', 'uplink'))),
}));