
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
express-serve-public
Advanced tools
Express Serve Public will generate an instant public URL for your express application. This URL will work behind firewalls and will connect to your local machine via a tunnel. You don't need any special networking config or setup. It will work behind NAT and CG-NAT.
Behind the scenes, this uses Tunnelmole (an open source ngrok
alternative) to get the public URLs.
Add express-serve-public
to your project with npm
npm install --save express-serve-public
First you'll need to import the servePublic
module. Both ES and CommonJS style imports are supported.
ES style import:
import { servePublic } from 'express-serve-public`;
CommonJS style import:
const servePublic = require('express-serve-public/cjs');
Here is a full example express application which will generate a randomized public URL at launch
// app.js
import { Request, Response } from "express";
import { servePublic } from "../src/servePublic.js";
import express from "express";
/**
* An example to get an instant public URL for your express app.
*
* Heavily based on the Hello World example from https://expressjs.com/en/starter/hello-world.html
*/
const app = express();
app.get("/", (request, response) => {
response.send("Hello World!");
});
servePublic(
app,
{
port: 3000,
}, () => {
console.log(`Example app listening on port 3000`);
}
);
If your project is using CommonJS, here is a CommonJS example: https://github.com/robbie-cahill/express-serve-public/blob/main/cjs/express-serve-public.js.
When this application runs, you should see output similar to the following:
Example app listening on port 3000
http://kqr4cc-ip-157-211-195-169.tunnelmole.com is forwarding to localhost:3000
https://kqr4cc-ip-157-211-195-169.tunnelmole.com is forwarding to localhost:3000
The express application has started and is listening on port 3000. Tunnelmole has generated a public URL that is pointing to your express application.
Try hitting one of these URLs from any device on the internet and like magic they will connect to your locally running express server.
Well not exactly magic, heres how it works.
Sometimes, it can be useful to have a URL that does not change and for that, Tunnelmole supports custom subdomains.
To get a URL that does not change, pass in the domain
option to servePublic
as follows:
servePublic(
app,
{
port: 3000,
domain: '<yourdomain>.tunnelmole.com`
}, () => {
console.log(`Example app listening on port 3000`);
}
);
If you are using the hosted service (which is the default) and you want to use a custom subdomain you'll need to purchase a subscription Learn More.
Otherwise, you can self host as the service is also open source so nothing prevents you from running your own server, no subscriptions needed. To learn more about this option go to the Tunnelmole Service GitHub repo.
Tunnelmole is available as a standalone CLI application (npm install -g tunnelmole
) and as an NPM dependency for use with other projects such as React for example. Get it from (https://github.com/robbie-cahill/tunnelmole-client).
This project uses the dependency to give you a nice wrapper function to use with express
.
FAQs
Instant Public URLs for Express
We found that express-serve-public demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.