Skip to content

Commit 0f67517

Browse files
committed
docs: update tunnel example code to check for and install cloudflared binary if missing
1 parent 779c35b commit 0f67517

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

examples/tunnel.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
const { Tunnel } = require("cloudflared");
1+
const fs = require("node:fs");
2+
const { Tunnel, bin, install } = require("cloudflared");
23

34
console.log("Cloudflared Tunnel Example.");
45
main();
56

67
async function main() {
8+
if (!fs.existsSync(bin)) {
9+
// install cloudflared binary
10+
await install(bin);
11+
}
12+
713
// run: cloudflared tunnel --hello-world
814
const tunnel = Tunnel.quick();
915

examples/tunnel.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
import { Tunnel } from "cloudflared";
1+
import fs from "node:fs";
2+
import { Tunnel, bin, install } from "cloudflared";
23

34
console.log("Cloudflared Tunnel Example.");
45
main();
56

67
async function main() {
8+
if (!fs.existsSync(bin)) {
9+
// install cloudflared binary
10+
await install(bin)
11+
}
12+
713
// run: cloudflared tunnel --hello-world
814
const tunnel = Tunnel.quick();
915

0 commit comments

Comments
 (0)