node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org »

server-address

Server Address

NPM version NPM Downloads Build status Test coverage Greenkeeper badge

Listen to a randomly available port and resolve urls relative to the server address.

Installation

npm install server-address --save

Usage

var serverAddress = require('server-address')
var express = require('express')
var app = express()
 
var server = 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.

TypeScript

Includes a TypeScript type definition.

License

MIT license