So I'm trying to parse host string ("asd.com:123" for example) to obtain domain name and port. It looks like node.js has build-in URL module just for this. However it doesn't work as I expect (maybe it's supposed to parse only fully-qualified URLs?). Is there any other way to perform this?
var urlModule = require('url');
var stringToParse = 'asd.com:123';
var parseResult = urlModule.parse(stringToParse);
console.log(parseResult);
output:
{ protocol: 'asd.com:',
slashes: null,
auth: null,
host: '123',
port: null,
hostname: '123',
hash: null,
search: null,
query: null,
pathname: null,
path: null,
href: 'asd.com:123' }