node .
Server running on port 3030
- Go to http://localhost:3030
- Click the
Exec shell command
- See the terminal to check for the output
Calling API at http://localhost:3030/exec
See terminal
, these should be the output
this is shell script
$0 = ./public/script.sh
$1 = device0
$2 = 127.0.0.1
index.js line 20
app.get('/exec',(req,res,next)=>{
const shell = require('shelljs')
shell.exec('echo Executing, shellJS')
shell.exec('echo Hello, hello')
shell.exec('echo good bye')
})
For more supported shell commands in ShellJS
refer to https://github.com/shelljs/shelljs
See public/index.html
NodeJS support to exec shell command built-in by default
const {exec} = require('child_process')
function execute(cmd,cb) {
exec(cmd, (err,stdout,stder)=>{
if (typeof(cb)==='function') cb(stdout)
})
return null
}
execute("echo hello", s=>{
console.log(s)
})
ShellJS helps simplify using it with a lot of other handlers.