NodeJS and Raspberry Pi

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);
  }
}