Friday, March 28, 2014

Would understanding streams help avoid errors with Readline?

When I try to run this: var readline = require('readline'); var rl = readline.createInterface({ input: process.sdtin, output: process.stdout, }); rl.question("What do you think of node.js?", function(answer) { // TODO: Log the answer in a database console.log(answer + ',Thank you for your valuable feedback.'); // These two lines together allow the program to terminate. Without // them, it would run forever. i.close(); process.stdin.destroy(); }); I get this: readline.js:833 if (stream._keypressDecoder) return; ^ TypeError: Cannot read property '_keypressDecoder' of undefined at Object.emitKeypressEvents (readline.js:833:13) at new Interface (readline.js:118:13) at Object.exports.createInterface (readline.js:39:10) at Object. (/home/shambaughlab/node_examples/seh1_readline.js:3:19) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) I am unsure, but maybe I should look at streams.

Sunday, March 16, 2014

WebPayments Use Cases

I've been spending the past few weeks with others such as Natasha Rooney, Marcos Caceres, and Manu Sporny working on some WebPayments Use Cases for the first W3C Webpayments workshop (1). They are illustrated here: , but also here: and here: . I'm trying to get things narrowed down so that Marcos' suggestions can be included:


Saturday, March 1, 2014

Control Flow in Node.js -- this is not working

When I run this code, I only see the first readline with, "Should I make a career change?". Perhaps this has something to do with program flow in the language.

Here is the code:

readline = require('readline');

var fs = require('fs');

var answer = 'the wrong answer';

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,

rl.question("Should I change?", function(answer) {
write(answer + ', I should change.');

 rl.question("Should I stay the same?", function(myanswer) {
 mywrite(myanswer + ', I should stay the same.');

function write(answer) {
fs.writeFile('career_change.txt', answer , function(err) {

function mywrite(myanswer) {
fs.writeFile('career_change.txt', myanswer , function(err) {

Here is Mixu's chapter on control flow in Node.js: