npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kriper0nind/wg-utils

v1.3.0

Published

Wireguard tools core module

Readme

@kriper0nind/wg-utils

A powerful TypeScript library for programmatically managing WireGuard VPN configurations.

Quick Start

npm install @kriper0nind/wg-utils
import { 
  generateKeys, 
  generatePresharedKey, 
  initConf, 
  addPeer, 
  up 
} from "@kriper0nind/wg-utils"

// 1. Generate server keys
const serverKeys = await generateKeys()

// 2. Create server configuration
await initConf("/etc/wireguard/wg0.conf", {
  privateKey: serverKeys.privateKey,
  port: 51820,
  ip: "10.0.0.1",
  dns: "1.1.1.1"
})

// 3. Add a client
const clientKeys = await generateKeys()
const { presharedkey } = await generatePresharedKey()
const result = await addPeer("/etc/wireguard/wg0.conf", {
  publicKey: clientKeys.publicKey,
  presharedKey: presharedkey,
  persistentKeepalive: 25
})

// 4. Start the VPN
await up("wg0")

console.log(`Client IP: ${result.ip}`) // "10.0.0.2"

Features

  • 🔑 Key Management - Generate WireGuard key pairs securely
  • ⚙️ Configuration Management - Parse, modify, and stringify configs
  • 👥 Peer Management - Add/remove peers with automatic IP assignment
  • 🔌 Interface Control - Start/stop WireGuard interfaces programmatically
  • 🩺 Live Monitoring - Sync running configs and inspect handshakes
  • 🛡️ Type Safety - Full TypeScript support
  • Easy to Use - Simple, intuitive APIs

Core Functions

Configuration Management

  • parse(configText) - Parse WireGuard configs into JavaScript objects
  • stringify(config) - Convert config objects back to WireGuard format

Key Operations

  • generateKeys() - Generate new key pairs
  • generatePresharedKey() - Create preshared keys for extra security
  • getPubKey(filepath) - Extract public key from private key

Server Management

  • initConf(filepath, options) - Create initial server configuration with DNS/MTU/PostUp overrides
  • up(iface) / down(iface) - Control WireGuard interfaces

Peer Management

  • addPeer(filepath, options) - Add peers with auto IPs, PSKs, endpoints, keepalives
  • deletePeer(filepath, { publicKey }) - Remove peer by public key

Monitoring & Maintenance

  • getLatestHandshake(iface) - Inspect live peer activity and transfer stats
  • syncConf(iface) - Keep running interfaces in sync with config files

Environment & Installation

  • checkWg() / requireWg() - Detect WireGuard availability
  • installWg(options) - Install WireGuard with platform-aware commands
  • getInstallInstructions() - Show commands without executing them

Examples

Basic Server Setup

import { generateKeys, initConf, up } from "@kriper0nind/wg-utils"

const keys = await generateKeys()
await initConf("/etc/wireguard/wg0.conf", {
  privateKey: keys.privateKey,
  port: 51820,
  ip: "10.0.0.1"
})
await up("wg0")

Add Multiple Clients

import { generateKeys, addPeer } from "@kriper0nind/wg-utils"

const clients = []
for (let i = 0; i < 5; i++) {
  const keys = await generateKeys()
  const result = await addPeer("/etc/wireguard/wg0.conf", {
    publicKey: keys.publicKey
  })
  clients.push({ ...keys, ip: result.ip })
}

Configuration Manipulation

import { parse, stringify } from "@kriper0nind/wg-utils"
import { readFile, writeFile } from "fs/promises"

// Read and modify configuration
const configContent = await readFile("/etc/wireguard/wg0.conf", "utf-8")
const config = parse(configContent)

config.Interface.ListenPort = 51821
config.Peers.push({
  PublicKey: "new-client-key",
  AllowedIPs: "10.0.0.10/32"
})

// Save changes
const newConfig = stringify(config)
await writeFile("/etc/wireguard/wg0.conf", newConfig)

Requirements

  • Node.js 16+
  • WireGuard installed
  • Root/sudo privileges for interface management
  • iptables for NAT functionality

Documentation

📖 Full Documentation - Complete API reference and guides

License

MIT © dsavelyev-man