This plugin adds a custom JavaScript node to NocoBase workflows, allowing users to execute custom JavaScript code within their workflows.
npm install @buzz-code/custom-js-node- Execute custom JavaScript code in workflows
- Access workflow context variables
- Full TypeScript support
- Internationalization support (English and Chinese)
- Add the plugin to your NocoBase application
- Create or edit a workflow
- Add a "Custom JavaScript" node
- Write your JavaScript code in the code editor
- Use the context object to access:
context.input- Input data from previous nodecontext.execution- Current workflow executioncontext.node- Current node instancecontext.processor- Workflow processor
// Double the input valueconst{ input }=context;return{result: input.value*2};The code execution is wrapped in a try-catch block. If your code throws an error, the node will fail gracefully and report the error message.
// Example with error handlingtry{const{ input }=context;if(!input.value){thrownewError('Input value is required');}return{result: input.value*2};}catch(error){thrownewError('Calculation failed: '+error.message);}The code is executed in a sandboxed environment using the Function constructor. However, you should still be careful about what code you allow to be executed, as it has access to the workflow context.
MIT