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
Instead of using the fibers npm module directly, we now have Meteor.bindEnvironment as stated here:
Future.wait() can't wait without a fiber (while waiting on another future in Meteor.method)
and here:
http://docs.meteor.com/#/full/renderable_content
Here is a working example. The output will be in terminal. Hope that helps.
terminal.html
<head>
<title>terminal</title>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<input type="text" id="command">
<input type="button" id="button" value="Click" />
</template>
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();
});
}
});
}