2. Define the server methods in server.js.
server/server.js
Meteor.startup(function () {
// Load future from fibers
var Future = Npm.require("fibers/future");
// Load exec
var exec = Npm.require("child_process").exec;
// Server methods
Meteor.methods({
runCode: function () {
// This method call won't return immediately, it will wait for the
// asynchronous code to finish, so we call unblock to allow this client
// to queue other method calls (see Meteor docs)
this.unblock();
var future=new Future();
var command="pwd";
exec(command,function(error,stdout,stderr){
if(error){
console.log(error);
throw new Meteor.Error(500,command+" failed");
}
future.return(stdout.toString());
});
return future.wait();
}
});
});
Sometimes we may want to preserve the environment variables of the original user when using sudo.
If you want to preserve all env variables, you could use the -E option. But use it with caution.
sudo -E bash -c 'echo $PATH'
A better approach is to list those env variables which u want to preserve in the sudoers config file. For example, i want to keep the HTTP_PROXY and HTTPS_PROXY.
If you need more statistical functions other than getting the mean value. You could try Simple Statistics.
Visit the above link and play with it. Here is an example on getting some common statistics value in Javascript.
// numbers from 1 to 100
var myData = [];
for (var i = 0; i < 99; i++) {
myData[i] = i + 1;
}
ss.mean(myData);
ss.min(myData);
ss.quantile(myData , 0.2);