function getPortFromConfig(cfg, key, defaultPort) {
  if (!cfg.PORTS) {
    return defaultPort;
  }
  if (!cfg.PORTS[key]) {
    return defaultPort;
  }
  if (parseAndTestIsNumber(cfg.PORTS[key])) {
    return parseInt(cfg.PORTS[key], 10);
  }
  return defaultPort;
}
Gets a value by its key from the config.PORTS and define a default.
Does some sanity checks if it is really a port we could use. Doesn't check if a port is in use
already.

@param cfg {Object} the config object loaded from disk
@param key {String} The key to lookup
@param defaultPort {Number} The  default port to assign if the value is not present
@returns port {Number} The port to use