This is our attempt at creating a "hello world" node. The node will print the string "hello world" to the console, and to the editor.
Head out to "handling inputs" or "handling outputs" for more advanced guides on building nodes that exchange data with other nodes.
Setting up the structure
Lets start of with creating a directory for our node.
Location
If you want to be able to play with this node immediately in XIBLE, ensure it is located in your nodes directory. There are two options;
- Use the default nodes directory used for downloading and installing nodepacks. You can find which directory that is by typing
xiblepm config get nodes.path
at the command line. - Alternatively, target the
./nodes
directory within your xible installation directory. If it does not exist yet, you can simply create it.
Within the nodes directory of your choosing, create a directory called "hello-world".
Creating the right files
After you have created the directory for your node, create the following empty files in that directory. The next chapters will be about giving those files some meaning.
- index.js
- structure.json
Setting up structure.json
Copy the following contents into your structure.json;
{
"name": "hello-world" // the name of your node as visible in XIBLE
"type": "action"
"inputs": { // inputs that connectors can be attached to
"trigger": { // name of the input
"type": "trigger" // triggered by an output trigger from another node
}
}
}
Be sure to remove the comments (starting with // ...
), as the JSON specification does not allow them.
index.js
With the structure setup, we need to specify how this node interacts with XIBLE and other nodes. XIBLE simply "requires" the directory where the structure.json can be found. By default, Node.js will pick up the index.js within a directory if the require is on a directory path.
'use strict';
// export a function to run when a flow containing this node initializes
module.exports = (NODE) => {
// get the input trigger we created in structure.json
const triggerIn = NODE.getInputByName('trigger');
// when another node triggers this input through a connector
triggerIn.on('trigger', (conn, state) => {
// assign a message and output it to console
const msg = 'hello world';
console.log(msg);
// add a status message visible in the editor
NODE.addStatus({
message: msg, // set the message
timeout: 3000 // remove the status message after 3 seconds
});
});
};
Run it
- Restart your XIBLE to pick up the new node.
- Create a new flow.
- Open the node selector, by double clicking the editor.
- Your "hello-world" node should be in the list. If not, check your XIBLE logs.
- Click your node to add it to the editor, you may drag it anywhere.
- Add a "xible.flow.onstart" node.
- Hook up the output trigger of the "xible.flow.onstart" node to the input trigger of your "hello-world" node.
- Hit "Deploy". Or alternatively, double click your "hello-world" node to run it in direct mode.