I'm trying to execute a Linux command from a webpage with node.js, socket.io and (I think...) PHP. I watched this YouTube video, and I'd like to do the same thing, but I don't know how.
Could you give me an example?
The link to their implementation is available in the GitHub repo linked in the video - mirceageorgescu/raspi-tank.
node.js is perfectly capable of running programs. A draft could look like the following.
Server
var exec = require('child_process').exec;
io.sockets.on('connection', function(socket) {
socket.on('exec', function(cmd) {
exec(cmd, function(err, stdout, stderr) {
// do something with the output or not
});
});
});
Client
socket.emit('exec', 'cat file.txt');
Information on how to start the socket on the server or connect to it from the client-side is available on socket.io.