Open
Description
the method createConnection
accepts a connection URL as a string or an object of type ConnectionConfig
if a string is passed, it uses require('url').parse
to parse the string and returns a connection object.
this approach assumes that the property pathname
that is returned by url.parse
has a string value, but in fact, it returns null when providing a port which is an integer
example
let's parse this connection URL string mysql://username:password@host:1234
const urlParse = require('url').parse;
let url = "mysql://username:password@host:123",
parsed = urlParse(url, true);
console.log(parsed)
output:
{
protocol: 'mysql:',
slashes: true,
auth: 'username:password',
host: 'host:123',
port: '123',
hostname: 'host',
hash: null,
search: null,
query: [Object: null prototype] {},
pathname: null, // <----------------------------------
path: null,
href: 'mysql://username:password@host:123'
}
note that pathname
here is null