Execute command



how to execute a command without using the exec node but in a function ?
and recover the value



What type of command?


actually, I did not mention…

a command cli linux


Why do you not want to use the exec node?


because I want to execute commands before others, I prefer to do it in my function. my program will be cleaner


You could do it in a python script search on the flows site for one of the python nodes.


@baudetd to do it in your function node you would need to use the child_process module from the node.js runtime.

You will need to:

  1. Use the functionGlobalContext setting to make the module available to the function node. See the nodered.org docs on writing functions for details
  2. Read the node.js docs.on the child_process module and seek out examples.

Which is of course just what the exec node does for you....


const { spawn } = require('child_process');
const ls = spawn('ls', ['-lh', '/usr']);

ls.stdout.on('data', (data) => {
msg.payload = msg.payload + (stdout: ${data});

ls.stderr.on('data', (data) => {
msg.payload = msg.payload +(stderr: ${data});

ls.on('close', (code) => {
msg.payload = msg.payload +(child process exited with code ${code});

but i have an error with " functionGlobalContext"
i Don't understand that

"ReferenceError: require is not defined (line 0, col 84)"


I would like to run a omxplayer command and be able to kill it in a function
thanks for your help


or use the pre-built node ? https://flows.nodered.org/node/node-red-contrib-pi-omxplayer


no , i know this but i Don't use the prebuilt node


As I said, you need to read the documentation on writing functions to learn how to require additional modules. You cannot require them directly.