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:

No comments:

Post a Comment