Interactive console input

Simple way to be able to use the Node-RED process console to interact with your flow via text input.

With the given flow, upon pressing the inject button the console will look like this:

4 Nov 16:35:02 - [info] Starting flows
4 Nov 16:35:02 - [info] Started flows
Who are you?█

Then upon typing an input and pressing Enter, the console will look like this:

4 Nov 16:35:02 - [info] Starting flows
4 Nov 16:35:02 - [info] Started flows
Who are you?Foo Bar
Hey there Foo Bar!

And additionally the input is sent to the debug console.

Credit to this post for the example: https://www.codecademy.com/articles/getting-user-input-in-node-js

[{"id":"5da98edae7a210d0","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"c509a2b7c658cb81","type":"function","z":"5da98edae7a210d0","name":"","func":"if(context.get(\"busy\")) return;\ncontext.set(\"busy\",true);\nnode.status({\"fill\":\"red\",\"text\":\"BUSY\"});\n\nvar cmdline = readline.createInterface({\n    input: process.stdin,\n    output: process.stdout\n});\n \ncmdline.question('Who are you?', name => {\n    console.log(`Hey there ${name}!`);\n    msg.payload = name;\n    node.send(msg);\n    cmdline.close();\n    context.set(\"busy\",false);\n    node.status({});\n});\n","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\ncontext.set(\"busy\",false);","finalize":"","libs":[{"var":"readline","module":"readline"},{"var":"process","module":"process"}],"x":360,"y":120,"wires":[["799e33757c87386e"]]},{"id":"3b470373578a6274","type":"inject","z":"5da98edae7a210d0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":120,"wires":[["c509a2b7c658cb81"]]},{"id":"799e33757c87386e","type":"debug","z":"5da98edae7a210d0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":120,"wires":[]}]

Flow Info

Created 3 years, 9 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x1)
  • inject (x1)
Other
  • tab (x1)

Tags

  • console
  • input
  • interactive
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option