Executes a command in a shell and buffers the output. The entire output is made available at once in the callback when the process exits.
A childPrcoess object, but the output (stdout and stderr) is passed to a callback function rather than streamed.
Buffers all data into memory, so it's not ideal for large amounts of output.
Simpler than spawn() for commands with smaller or one-off outputs
spawns a shell and runs a command within that shell, passing the stdout and stderr to a callback function when complete.
The exec method is used to run shell commands in a child process. It's handy when you need to execute external programs or shell scripts from your Node.js application. We pass a command string as an argument to exec, and it spawns a shell to execute that command.
exec doesn't provide a direct way to communicate with the child process. However, you can capture its output and error streams to get the results of the command it executed.
child_process.exec(): spawns a shell and runs a command within that shell, passing the stdout and stderr to a callback function when complete.
child_process.execFile(): similar to child_process.exec() except that it spawns the command directly without first spawning a shell by default.
child_process.execSync(): a synchronous version of child_process.exec() that will block the Node.js event loop.
child_process.execFileSync(): a synchronous version of child_process.execFile() that will block the Node.js event loop.