Skip to main content

Tunnels from Code

Serve your Node.js app at a stable https://<name>.tunnel.asyx.ai address from inside the app, with the app's own identity. No browser, no terminal left open, no shared device key.

Prerequisites

  • A computer set up with asyx setup (CLI 0.10.1 or later)
  • Node.js 18.17+ where the app runs

Step 1 — Create the app identity

On the set-up computer, in your project folder:

asyx app create orders-api

This gives the app its own key, certificate and address (orders-api.tunnel.asyx.ai). The key never leaves this computer: credentials are kept in ~/.asyx/apps/<appId>/, and the project gets only asyx.json, which holds no secrets and is safe to commit.

Pin the app to an address your account already has instead:

asyx app create orders-api --address fast

Step 2 — Hand the credentials to the machine that runs the app

asyx app export orders-api --out /secure/place/orders-api.json

The file is owner-only. Put it in your secret store and set ASYX_CREDENTIALS to its contents or its path. See App credentials for the rules.

Step 3 — Open the tunnel from the app

npm install @asyx/tunnel
import { Asyx } from '@asyx/tunnel';

const asyx = await Asyx.connect({ credentials: Asyx.credentialsFromEnv() });
const tunnel = await asyx.http({ port: 3000 });
console.log(`Serving ${tunnel.url}`);

Your app keeps listening on its own port; the tunnel forwards visitors to localhost:3000. Renewal and reconnects happen inside the library.

When the app stops, await tunnel.close() releases the address at once. The library also does this on SIGINT and SIGTERM.

What can go wrong

ErrorMeaning
HostnameNotAssignedErrorYou passed a hostname that is not the app's own address. An app serves only its own address.
AddressInUseErrorThe address already has a live tunnel (another copy of the app, or a device of your account). error.details says where. Pass replace: true to take it over.
RevokedErrorThe app was revoked or deleted in the console.
CredentialsErrorASYX_CREDENTIALS is missing or not the JSON from asyx app export.

The library never calls process.exit and never logs credentials or request bodies. Pass a logger to Asyx.connect to see what it does.

Try it from the CLI first

asyx tunnel --http --port 3000 --app orders-api

This runs a tunnel with the app's identity, the same way the library does.