Virtual Node Development (Graph)
A detailed guide on the concept of a Virtual Node - a technique that allows you to group and package multiple functional Nodes into a single Node, export it, and share it via NPM.
What is a Virtual Node?
Virtual Node (also known as a Sub-Workflow) is a solution that helps you abstract complex logic (consisting of multiple inter-connected Nodes) into a single, clean node.
Instead of scripting logic in JavaScript (like a traditional Community Node), you can simply drag and drop existing Nodes on the nLink Builder to create a Workflow, which gets saved as JSON. A Virtual Node can then be published to the NPM registry just like any other Node.
Standard Directory Structure
Taking the nlink-community.graphNode as an example, since it doesn't require a JavaScript execution script (execution.js), the directory only contains 2 simple files:
nlink-community.graphNode/
├── package.json # NPM configuration & nLink package identification
└── definition.json # The core file containing Node definitions and Workflow Data (Graph Data)Exploring definition.json elements
Inside the definition.json of a Virtual Node, there are two primary components: schema (UI definition) and graph_data (the workflow logic).
- The "schema" Block
Contains identity information identical to regular nodes. Thepropertiesarray will act as the "input variables" for your workflow."schema": { "name": "nlink-community.graphNode", "displayName": "graphNode", "group": ["community"], "icon": "bi-box", "properties": [ // Define Authentication portals or Workflow Parameters here... ] } - The "graph_data" Block
This is where your orchestration structure shines, containing the whole structure of internal nodes (nodes) and their connections (connections)."graph_data": { "nodes": [ { "type": "nlink-virtual.input", "name": "Virtual Node Input" }, { "type": "nlink-base.httpRequest", "name": "HTTP Request 1" }, { "type": "nlink-base.httpRequest", "name": "HTTP Request 2" }, { "type": "nlink-base.merge", "name": "Merge" }, { "type": "nlink-virtual.output", "name": "Virtual Node Output" } ], "connections": { ... } } - Virtual Input & Output (The Core Elements)
Insidegraph_data, there must always exist two special routing nodes:nlink-virtual.inputandnlink-virtual.output. They act as gateways to receive data from the Virtual Node's external inputs and return execution results from the internal loop.
Publishing Process (NPM)
Once you have exported the JSON file containing the graph_data from the nLink Editor, the process is identical to a Community Node:
# 1. Initialize an accurate package.json
npm init
# 2. Login and push it to the public NPM registry
npm publish --access public