You need to use Node.js if you want to use server-side JavaScript.
Something like this:
var express = require('express')
var app = express()
const { exec } = require("child_process");
// when navigating to your http://<yourdomain>/shutdown
app.get('/shutdown', function (req, res) {
exec("sudo shutdown -h now", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…