Skip to content

Share localhost / Express

Share an Express app at a public URL

An Express app listens on the port you give app.listen, 3000 in the docs' hello world, and whk share 3000 gives that port an HTTPS link. Express checks no host, so every route answers at once. What it gets wrong until you tell it about the proxy is the protocol, the hostname and the client address.

# terminal 1: the dev server
node app.js

# terminal 2: the link
whk share 3000

The link is https://<name>.sharehooks.cc and works until you press Ctrl-C. No whk yet? Install it and log in, which takes a minute.

Start free:
or sign up with email

Express at a glance

Dev server
node app.js, port 3000
Share it
whk share 3000
Setting to add
No host setting. app.set('trust proxy', 'loopback') so Express reads X-Forwarded-* from the link.
Without it
No error. req.protocol is http, req.hostname is localhost, req.ip is 127.0.0.1, and a session cookie marked secure: true is never set.
Hot reload
Express has no reload of its own. Restart tools restart the server, and visitors see the change on their next request.
URLs and cookies
With trust proxy, req.hostname and req.host are the public name, req.protocol is https and req.ip is the visitor. req.get('host') stays localhost:3000.

Your dev server gets each request with Host: localhost:3000; the public name travels in X-Forwarded-Host, with X-Forwarded-Proto: https. What your server sees has the rest.

Tell Express it is behind a proxy

By default Express treats itself as facing the client directly: req.protocol comes from the socket, req.hostname from the Host header and req.ip from the connection. Through the link those are http, localhost and 127.0.0.1, because the request reaches your app from whk on your own machine.

The trust proxy setting tells Express which addresses may speak for the client. whk connects from loopback, so trust loopback and nothing wider:

app.js

const express = require("express");
const app = express();

// whk share connects from this machine
app.set("trust proxy", "loopback");

Now req.protocol is https, req.secure is true, req.hostname is <name>.sharehooks.cc and req.ip is the visitor's address. req.host (which keeps a port in Express 5) follows too. req.get('host') reads the raw header and still says localhost:3000, so build absolute URLs from req.protocol and req.host.

Secure session cookies

express-session does not set a cookie marked secure: true on a connection it believes is plain HTTP. Without trust proxy that is every request through the link, and the symptom is a login that never sticks: the response simply carries no Set-Cookie.

With trust proxy set as above, the session cookie goes out with Secure and the visitor's browser, which is on HTTPS, keeps it. cookie: { secure: 'auto' } picks the right value on localhost and on the link alike. Leave the cookie's domain unset: a cookie for another domain is dropped on the way out.

Redirects, WebSockets and reloads

res.redirect('/login') sends a path, which works on any origin. A redirect to http://localhost:3000/... is also returned to the link. WebSocket servers attached to the same HTTP server, ws or Socket.IO among them, come through on the same port.

There is no dev server in Express and so no browser reload: tools that restart Node on change restart your app, and a visitor's next request reaches the new code. If nothing is listening during a restart, the visitor gets a short page saying so rather than a broken connection.

Express questions

Sources

The Express settings and messages on this page are from the official documentation for Express 5.3, read on 12 November 2026. What the link does to a request is from the whk share docs.

Other frameworks

All 14 framework guides

Send someone your Express app

Sign up free, install the CLI and run whk share 3000.

or sign up with email

No credit card