async function createNode(flow,config) {
    var newNode = null;
    var type = config.type;
    try {
        var nodeTypeConstructor = typeRegistry.get(type);
        if (typeof nodeTypeConstructor === "function") {
            var conf = jsonClone(config);
            delete conf.credentials;
            try {
                Object.defineProperty(conf,'_module', {value: typeRegistry.getNodeInfo(type), enumerable: false, writable: true })
                Object.defineProperty(conf,'_flow', {value: flow, enumerable: false, writable: true })
                Object.defineProperty(conf,'_path', {value: `${flow.path}/${config._alias||config.id}`, enumerable: false, writable: true })

                for (var p in conf) {
                    if (conf.hasOwnProperty(p)) {
                        mapEnvVarProperties(conf,p,flow,conf);
                    }
                }
                newNode = new nodeTypeConstructor(conf);
            } catch (err) {
                Log.log({
                    level: Log.ERROR,
                    id:conf.id,
                    type: type,
                    msg: err
                });
            }
        } else if (nodeTypeConstructor) {
            // console.log(nodeTypeConstructor)
            var subflowConfig = parseConfig([nodeTypeConstructor.subflow].concat(nodeTypeConstructor.subflow.flow));
            var subflowInstanceConfig = subflowConfig.subflows[nodeTypeConstructor.subflow.id];
            delete subflowConfig.subflows[nodeTypeConstructor.subflow.id];
            subflowInstanceConfig.subflows = subflowConfig.subflows;
            var instanceConfig = jsonClone(config);
            instanceConfig.env = jsonClone(nodeTypeConstructor.subflow.env);

            instanceConfig.env = nodeTypeConstructor.subflow.env.map(nodeProp => {
                var nodePropType;
                var nodePropValue = config[nodeProp.name];
                if (nodeProp.type === "cred") {
                    nodePropType = "cred";
                } else {
                    switch(typeof config[nodeProp.name]) {
                        case "string": nodePropType = "str"; break;
                        case "number": nodePropType = "num"; break;
                        case "boolean": nodePropType = "bool"; nodePropValue == nodeProp?"true":"false"; break;
                        default:
                            nodePropType = config[nodeProp.name].type;
                            nodePropValue = config[nodeProp.name].value;
                    }
                }
                return {
                    name: nodeProp.name,
                    type: nodePropType,
                    value: nodePropValue
                }
            })

            var subflow = require("./Subflow").createModuleInstance(
                nodeTypeConstructor.type,
                flow,
                flow.global,
                subflowInstanceConfig,
                instanceConfig
            );
            // Register this subflow as an instance node of the parent flow.
            // This allows nodes inside the subflow to get ahold of each other
            // such as a node accessing its config node
            flow.subflowInstanceNodes[config.id] = subflow
            await subflow.start();
            return subflow.node;
        }
    } catch(err) {
        Log.error(err);
    }
    return newNode;
}
Create a new instance of a node
@param  {Flow} flow     The containing flow
@param  {object} config The node configuration object
@return {Node}          The instance of the node