wol

WakeOnLan

JSR: https://jsr.io/@hk/wol/

Node / Bun

import { wakeOnLan } from "wol-js";

// Resolves once the packet has been handed to the OS; rejects on bad input.
await wakeOnLan("70:a8:d3:b8:8c:8d", "255.255.255.255", 9);

CLI:

npx wol-js 70:a8:d3:b8:8c:8d --ip 255.255.255.255 --port 9

Deno

The Deno implementation uses Deno.listenDatagram, which is an unstable API. Run with --unstable-net, or add {"unstable": ["net"]} to your deno.json.

import { wakeOnLan } from "jsr:@hk/wol/deno";

await wakeOnLan("70:a8:d3:b8:8c:8d", "255.255.255.255", 9);

The jsr:@hk/wol entrypoint uses node:dgram through Deno’s node compatibility layer and needs no unstable flag.

The CLI (deno-cli.ts) is not part of the published package; run it from a checkout with deno task cli 70:a8:d3:b8:8c:8d.

MAC address formats

Both entrypoints accept 12 hex characters (aabbccddeeff) or six hex pairs separated by ., : or -. Anything else throws instead of silently sending a malformed packet.

Development

bun install
bun run build   # emits dist/mod.js, dist/cli.js and the .d.ts files
deno check src/deno-mod.ts deno-cli.ts

Breaking changes in 0.2.0

wakeOnLan now rejects when the send fails, where it previously logged the error to the console and resolved anyway. Its promise also resolves only once the packet has actually been handed to the operating system, rather than while it is still queued.

Callers that ignore the returned promise will therefore see an unhandled rejection on failure, which terminates Node by default. Await the call and handle the error:

try {
  await wakeOnLan("70:a8:d3:b8:8c:8d", "255.255.255.255", 9);
} catch (err) {
  console.error(err);
}

Malformed MAC addresses and out-of-range ports are also rejected now, where some previously produced a silently malformed packet.