Sure, let's generate a basic structure for a Node-RED node called "Pankaj".
package.json: This file holds various metadata relevant to the project. Here's a basic example:
json
{
"name": "node-red-contrib-pankaj",
"version": "0.0.1",
"description": "Pankaj Node-RED node",
"main": "pankaj.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"node-red": {
"nodes": {
"pankaj": "pankaj.js"
}
},
"keywords": [
"node-red"
],
"author": "Pankaj",
"license": "ISC"
}
pankaj.html: This file is used to define the node properties, edit dialog and help text. A basic example would be:
html
<script type="text/javascript">
RED.nodes.registerType('pankaj',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""}
},
inputs:1,
outputs:1,
icon: "file.png",
label: function() {
return this.name||"pankaj";
}
});
</script>
<script type="text/html" data-template-name="pankaj">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="pankaj">
<p>A simple Pankaj node</p>
</script>
pankaj.js: This file is used to define the runtime behavior of the node. A basic example would be:
javascript
module.exports = function(RED) {
function PankajNode(config) {
RED.nodes.createNode(this,config);
var node = this;
node.on('input', function(msg) {
msg.payload = "Pankaj node processed the message";
node.send(msg);
});
}
RED.nodes.registerType("pankaj",PankajNode);
}
Please replace the contents with your own logic