wireguard-config-parse
v1.0.0
Published
Parse a WireGuard .conf file into a plain object (Interface + Peers). Zero dependencies, comment-safe, coerces ports to numbers and lists to arrays.
Downloads
8
Maintainers
Readme
wireguard-config-parse
Parse a WireGuard .conf file into a plain object: one [Interface] and any
number of [Peer] sections. Zero dependencies, comment-safe. Ports become numbers
and comma-separated fields (Address, DNS, AllowedIPs) become arrays.
const parse = require('wireguard-config-parse');
parse(`[Interface]
PrivateKey = <key>
Address = 10.0.0.1/24
ListenPort = 51820
[Peer]
PublicKey = <key>
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = 203.0.113.5:51820
PersistentKeepalive = 25`);
// {
// interface: { PrivateKey:'<key>', Address:['10.0.0.1/24'], ListenPort:51820 },
// peers: [ { PublicKey:'<key>', AllowedIPs:['0.0.0.0/0','::/0'],
// Endpoint:'203.0.113.5:51820', PersistentKeepalive:25 } ]
// }Behaviour
- Lines starting with
#or;, and inline#comments, are ignored. ListenPort,PersistentKeepalive,MTU,FwMarkare coerced to numbers.Address,DNS,AllowedIPsare split into arrays on commas.- Unknown sections are ignored; a missing
[Interface]yieldsinterface: null.
Honest note: this parses structure and values only. It does not validate that keys are cryptographically valid or that the config actually connects.
Notes
Maintained by the team behind VPNSmith, a self-hosted VPN resource. For plain-English guides on WireGuard and running your own VPN, see vpnsmith.com.
License
MIT
