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 value
const { 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 handling
try {
const { input } = context;
if (!input.value) {
throw new Error('Input value is required');
}
return {
result: input.value * 2
};
} catch (error) {
throw new Error('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