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-terminal-app-with-meteor-js.html
The result is just blank when on the client side (Mac OSX Mavericks) I type in a command and hit the "Run" button. I am using the exact code from the site above, except that I have autorun and exec = Npm.require('child_process').exec;
Below are my html and js files...
TerminalApp.html
<head>
<title>MeteorJS terminal</title>
</head>
<body>
{{> terminal}}
</body>
<template name="terminal">
<pre>{{ window }}</pre>
<input id="command" type="text" value="{{ last_cmd }}" />
<input type="button" value="Run" />
</template>
TerminalApp.js
// A collection for stdouts
var Replies = new Meteor.Collection('replies');
if(Meteor.is_client) {
// Start listening changes in Replies
Meteor.autorun(function() {
Meteor.subscribe('replies');
});
// Set an observer to be triggered when Replies.insert() is invoked
Replies.find().observe({
'added': function(item) {
// Set the terminal reply to Session
Session.set('stdout', item.message);
}
});
// Show the last command in input field
Template.terminal.last_cmd = function() {
return Session.get('last_cmd');
};
// Show the last shell reply in browser
Template.terminal.window = function() {
return Session.get('stdout');
};
// Add an event listener for Run-button
Template.terminal.events = {
'click [type="button"]': function() {
var cmd = $('#command').val();
Session.set('last_cmd', cmd);
// Call the command method in server side
Meteor.call('command', cmd);
}
};
}
if(Meteor.is_server) {
var exec;
// Initialize the exec function
Meteor.startup(function() {
exec = Npm.require('child_process').exec;
});
// Trigger the observer in Replies collection
Meteor.publish('replies', function() {
return Replies.find();
});
Meteor.methods({
'command': function(line) {
// Run the requested command in shell
exec(line, function(error, stdout, stderr) {
// Collection commands must be executed within a Fiber
Fiber(function() {
Replies.remove({});
Replies.insert({message: stdout ? stdout : stderr});
}).run();
});
}
});
}
What am I missing? How can I debug? Thanks in advance!
Here is a working example. The output will be in terminal. Hope that helps.
terminal.html
terminal.js
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