$ npm install --save url-ext
var urlExt = require('url-ext');
var url = 'http://www.xxx.com:8080/search?q=jerrywu#hello';
var hostnameWithProtocol = urlExt.parseHostnameWithProtocol(url);
console.log('hostnameWithProtocol: %s', hostnameWithProtocol); // http://www.xxx.com
The MIT License.