I'm using node to execute bash command on Linux. I need to stop and start apache server. Normally from bash you need to type:
sudo service apache2 stop
and you need to insert the password. To change that I modify the 'visudo' after modification is not asking for a password but when I run this from node I get error
Error: Command failed: /bin/sh -c sudo systemctl status apache2.service
sudo: no tty present and no askpass program specified
Where is the problem? The node code looks like that
app.get('/StatusTest', function(req, res){
exec("sudo systemctl status apache2.service", function(err, stdout){
if(err) throw err;
console.log(stdout);
res.render('statustest');
});
})