Skip to content

@node-net/netconfNETCONF for Node.js

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.

@node-net/netconf

A taste ​

Shell
npm install @node-net/netconf
ts
import { 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');
ts
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'))),
}));

Released under the MIT Licence.