listen-url

1.0.3 • Public • Published

listen-url

var http = require('http')
http.createServer(function(req, res) {
  res.write('Hello, world!')
  res.end()
}).listen(0, require('listen-url'))

output:

listening on http://0.0.0.0:56841

.on('url', cb)

disables the default behaviour (writing the URL to the console). the event listener gets the URL as argument. if you want to do more magic, you get {host, port} as second argument (host preformatted for an URL, so has brackets for IPv6) and the full untouched address object as the third argument.

var http = require('http')
http.createServer(function(req, res) {
  res.write('Hello, world!')
  res.end()
}).on('url', function(url) {
  console.log('Arr, mateys! We be sailin\' at ' + url + '!')
}).listen(0, require('./'))

output:

Arr, mateys! We be sailin' at http://0.0.0.0:33643!

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.3
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.3
    2
  • 1.0.2
    1
  • 1.0.1
    2
  • 1.0.0
    1

Package Sidebar

Install

npm i listen-url

Weekly Downloads

4

Version

1.0.3

License

BSD

Last publish

Collaborators

  • nathan7