I'm trying to learn the "q" library with node.
$ node -v // -> v0.6.6
I'm using the latest q.js from https://github.com/kriskowal/q/blob/master/q.js now. I copied the code into a q.js file which is the sibling of my testq.js file.
The code of testq.js is:
function step1(callback) { console.log("step1"); callback("abc"); };
var Q = require("./q");
Q.fcall(step1).end();
When I run it:
node testq.js
It reports:
E:\WORKSPACE_NODE\TestNodeJs\q>node testq.js
step1
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: undefined is not a function
at step1 (E:\WORKSPACE_NODE\TestNodeJs\q\testq.js:1:112)
at makePromise.<anonymous> (E:\WORKSPACE_NODE\TestNodeJs\q\q.js:541:27)
at makePromise.promiseSend (E:\WORKSPACE_NODE\TestNodeJs\q\q.js:325:41)
at Array.0 (E:\WORKSPACE_NODE\TestNodeJs\q\q.js:787:28)
at EventEmitter._tickCallback (node.js:192:40)
I installed v8 debugger plugin for eclipse, debug it line by line. Unfortunately, I can't find the error start.
I'm a newbie to nodejs, please help me with debugging. E.g. what tool should I use? Or any other helpful method I should try?
UPDATE
Per Hogan's answer, the code:
function step1(callback) { console.log("step1"); };
var Q = require("./q");
Q.fcall(step1).end();
can be run successfully without any error.
But when I try:
function step1(callback) { console.log("step1"); };
var Q = require("./q");
Q.fcall(step1)
.then(function(v) {
console.log("finished: " +v);
}, function(err){
console.log(err);
})
.end();
It prints:
E:\WORKSPACE_NODE\TestNodeJs\q>node testq.js
step1
finished: undefined
I still want a demo that step1 will pass something to the function(v) {console.log("finished: " +v);}, where v is not an undefined.
step1- socallbackis undefined