@o-town/expose
v1.5.0
Published
Expose localhost to *.site.com — zero dependencies, pure Node net
Downloads
134
Readme
expose
Zero-dependency tunnel — expose
localhostto*.site.comusing only Node's built-innetmodule.
http://localhost:3000 → https://abc1f3.site.comInstall & run (client)
# Run directly with npx (no install needed)
npx expose 3000
# Or install globally
npm install -g expose
expose 3000
# With a custom subdomain
expose 3000 myapp
# → https://myapp.site.comEnvironment variables
| Variable | Default | Description |
|-----------------|------------------|------------------------------|
| EXPOSE_SERVER | tunnel.site.com| Tunnel server hostname |
| EXPOSE_PORT | 2000 | Tunnel server TCP port |
Deploy the server on site.com
node server.js --http-port 80 --tunnel-port 2000 --domain site.comFlags / env vars
| Flag | Env var | Default |
|------------------|---------------|-------------|
| --http-port | HTTP_PORT | 80 |
| --tunnel-port | TUNNEL_PORT | 2000 |
| --domain | DOMAIN | site.com |
Keep alive with PM2
npm i -g pm2
pm2 start server.js --name expose-server -- --http-port 80 --domain site.com
pm2 save && pm2 startupnginx + TLS (recommended)
Issue a wildcard cert first:
certbot certonly --manual --preferred-challenges dns -d "*.site.com" -d "site.com"Then add a site config:
server {
listen 443 ssl;
server_name *.site.com;
ssl_certificate /etc/letsencrypt/live/site.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/site.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}How it works
Browser
│ HTTPS → nginx → port 80
▼
server.js (http.Server — public)
│ JSON line over TCP socket (port 2000)
▼
expose.js (net.createConnection — your machine)
│ http.request
▼
localhost:3000- Client opens a raw TCP socket to
site.com:2000and sends aregistermessage. - Server assigns a subdomain and replies
readywith the public URL. - Browser hits
https://abc1f3.site.com→ nginx → server's HTTP listener. - Server sends a
requestJSON line over the TCP socket. - Client forwards it to
localhost:PORT, gets the response, sendsresponseback. - Server writes the response to the waiting browser connection.
Zero dependencies. No WebSocket. No npm installs. Pure Node.
