I am new to Meteor and want to make a simple app. I am failing to simulate the command line on the server side according to http://terokaisti.blogspot.com/2012/10/writing-termin
Here is a working example. The output will be in terminal. Hope that helps.
terminal.html
terminal
{{> hello}}
terminal.js
Replies = new Meteor.Collection('replies');
if (Meteor.isClient) {
Template.hello.greeting = function () {
return "Welcome to terminal.";
};
Template.hello.events({
'click #button': function () {
console.log("clicking");
var cmd = $("input#command").val();
console.log("command", cmd);
var replyId = Meteor.call('command', cmd);
Session.set('replyId', replyId);
}
});
}
if (Meteor.isServer) {
exec = Npm.require('child_process').exec;
Meteor.methods({
'command' : function(line) {
console.log("In command method", line);
Fiber = Npm.require('fibers');
exec(line, function(error, stdout, stderr) {
console.log('Command Method', error, stdout, stderr);
Fiber(function() {
Replies.remove({});
var replyId = Replies.insert({message: stdout ? stdout : stderr});
return replyId;
}).run();
});
}
});
}