I have now been running Raspbian on Raspberry Pi and I would like to make a control panel for it, so I can control my Raspberry Pi in a web browser. But how do I execute commands in NodeJS?
You can use this node.js code to run commands on raspberry pi (the below is a sample to execute a reboot command on raspberry pi)
var exec = require('child_process').exec;
function execute(command, callback) {
var cmd = exec(command, function(error, stdout, stderr) {
console.log("error: " + error);
callback(stdout);
});
}
function reStart() {
try {
console.log("Reboot");
execute('sudo reboot', function(callback) {
});
}
catch (err) {
console.log(err);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With