Child Process
Child Process is a built-in module in Node.js. It is used to run commands in the terminal.
This implementation in Djot is a wrapper around the built-in module.
To use it in your application, import it from #djot/child_process
, and the first argument is the method you want to use from the built-in module.
The methods are promisified
, so you can use async/await
with them.
Full NodeJS documentation: https://nodejs.org/api/child_process.html
Note
The exec
method is used in the example below, but you can use any of the methods from the built-in module.
Beta Note
The current imeplementation and documentation is in beta and is subject to change.
The current implementation is a patch solution to allow the use of the built-in module in Djot - it is not the final solution.
Usage
import childProcess from '#djot/child_process'
const exec = (...args) => childProcess('exec', ...args)
export const App = () => {
const [output, setOutput] = React.useState('')
const handleClick = async () => {
const { stdout } = await exec('ls', ['-a'])
setOutput(stdout)
}
return (
<>
<button onClick={handleClick}>Run</button>
<pre>{output}</pre>
</>
)
}
import childProcess from '#djot/child_process'
const exec = (...args) => childProcess('exec', ...args)
export const App = () => {
const [output, setOutput] = React.useState('')
const handleClick = async () => {
const { stdout } = await exec('ls', ['-a'])
setOutput(stdout)
}
return (
<>
<button onClick={handleClick}>Run</button>
<pre>{output}</pre>
</>
)
}