0

I have the following two Node.js files:

//test.js
var hash=require('./hash');
var sys=require('sys');

hash.hash("asdf",function(param){
        sys.puts(param);
});

and

//hash.js:
var exec=require('child_process').exec;
var sys=require('sys');

exports.hash=function(data,callback){
        exec("./a.out "+data,function callback(error,stdout,stderr){
                callback(stdout);
        });
}

As you can see, I'm trying to make stdout available in test.js

Trouble is, when I run node test.js, I get the following error:

eamorr@Compaq6000:~/Desktop/simple-hash$ node test.js 

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
RangeError: Maximum call stack size exceeded

Anyone got any ideas as to what I might be doing wrong?

Many thanks in advance,


Edit: solution: rename the inner "callback" to "callback2" or something else... Thanks to Idan K for pointing this out.

1 Answer 1

1

When you call exec you are naming what should be an anonymous function, callback. This has the same name as the second argument to hash, hence the recursion.

Sign up to request clarification or add additional context in comments.

2 Comments

yes, I just realised this! Thank you so much for pointing that out. bangs head off desk
@Eamorr: there's actually no need to give it a name, but changing the name will fix it too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.