diff --git a/packages/server/src/NodesPool.ts b/packages/server/src/NodesPool.ts index 0ec14b86ffa..d30318bd096 100644 --- a/packages/server/src/NodesPool.ts +++ b/packages/server/src/NodesPool.ts @@ -24,11 +24,20 @@ export class NodesPool { * Initialize nodes */ private async initializeNodes() { - const disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : [] const packagePath = getNodeModulesPackagePath('flowise-components') const nodesPath = path.join(packagePath, 'dist', 'nodes') - const nodeFiles = await this.getFiles(nodesPath) - return Promise.all( + const nodes = await this.loadNodesFromDir(nodesPath) + Object.assign(this.componentNodes, nodes) + } + + /** + * Load and filter nodes from a directory. + */ + async loadNodesFromDir(dir: string): Promise { + const disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : [] + const nodes: IComponentNodes = {} + const nodeFiles = await this.getFiles(dir) + await Promise.all( nodeFiles.map(async (file) => { if (file.endsWith('.js')) { try { @@ -69,7 +78,7 @@ export class NodesPool { const isDisabled = disabled_nodes.includes(newNodeInstance.name) if (conditionOne && conditionTwo && !isDisabled) { - this.componentNodes[newNodeInstance.name] = newNodeInstance + nodes[newNodeInstance.name] = newNodeInstance } } } catch (err) { @@ -78,6 +87,7 @@ export class NodesPool { } }) ) + return nodes } /**