Listen to a randomly available port and resolve URLs relative to the server address.
npm install server-address --save
import { ServerAddress } from "server-address";
import * as express from "express";
const app = express();
const server = new ServerAddress(app);
// Listen to randomly available port.
server.listen();
server.url("/foo"); //=> "http://127.0.0.1:58933/foo"
// Close the server connection.
server.close();
Note: listen
and close
can optionally accept callback functions.
MIT license