-
Notifications
You must be signed in to change notification settings - Fork 4
Require
cflurin edited this page Aug 21, 2018
·
2 revisions
The methods can include external modules, example var os = require('os');
{
"methods": {
"onTransition": [
"var os = require('os');",
"var hostname = os.hostname();",
"msg.payload = 'host: ' + hostname + '; dir: ' + __dirname;",
"output = true;"
],
"status": {
"shape": "dot",
"text": {
"get": "msg.payload"
}
}
}
}
[{"id":"3f70b80d.fd6708","type":"dsm","z":"12f1321f.454d1e","name":"require","sm_config":"{\n \"methods\": {\n \"onTransition\": [\n \"var os = require('os');\",\n \"var hostname = os.hostname();\",\n \"msg.payload = 'host: ' + hostname + '; dir: ' + __dirname;\",\n \"output = true;\"\n ],\n \"status\": {\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"msg.payload\"\n }\n }\n }\n}\n","x":260,"y":580,"wires":[["ba7a5bf7.9b74a8"]]},{"id":"fd9d2f22.4aa8b","type":"inject","z":"12f1321f.454d1e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":580,"wires":[["3f70b80d.fd6708"]]},{"id":"ba7a5bf7.9b74a8","type":"debug","z":"12f1321f.454d1e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":410,"y":580,"wires":[]}]
{
"methods": {
"onTransition": [
"var exec = require('child_process').exec;",
"var cmd = 'npm view node-red-contrib-dsm version';",
"exec(cmd, function(error, stdout, stderr) {",
" msg.payload = 'version ' + stdout.trim();",
" node.send(msg);",
"});"
],
"status": {
"fill": "blue",
"shape": "dot",
"text": "reading ..."
}
}
}
[{"id":"3f70b80d.fd6708","type":"dsm","z":"12f1321f.454d1e","name":"get version","sm_config":"{\n \"methods\": {\n \"onTransition\": [\n \"var exec = require('child_process').exec;\",\n \"var cmd = 'npm view node-red-contrib-dsm version';\",\n \"exec(cmd, function(error, stdout, stderr) {\",\n \" msg.payload = 'version ' + stdout.trim();\",\n \" node.send(msg);\",\n \"});\"\n ],\n \"status\": {\n \"fill\": \"blue\",\n \"shape\": \"dot\",\n \"text\": \"reading ...\"\n }\n }\n}\n","x":280,"y":580,"wires":[["ba7a5bf7.9b74a8"]]},{"id":"fd9d2f22.4aa8b","type":"inject","z":"12f1321f.454d1e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":580,"wires":[["3f70b80d.fd6708"]]},{"id":"ba7a5bf7.9b74a8","type":"debug","z":"12f1321f.454d1e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":580,"wires":[]}]