Mel  Adane Mel Adane - 1 year ago 198
Node.js Question

Node async.js: callback is not a function error?

I have this code:

async = require('async'){
getUserName: function(callback) {
console.log('**In getUserName.**')
callback(null, 'Lem')

connectToDb: function(callback) {
console.log('**In connectToDb.**')
var connected = true
if(connected) {
callback(null, connected)
} else {
callback('Error connecting to DB.', null)

checkIfUserExist: [
function(callback, results) {
console.log('**In checkIfUserExist.**',
var userExist = false
if(userExist) {
callback('User exist in DB.')
} else {
function() {
callback(null, userExist);

signup: [
function(callback, results) {
console.log('**In signup**', JSON.stringify(results))
var userName = results.getUserName
var isDbConnected = results.connectToDb
var userExist = result.checkIfUserExist

if(userName && isDbConnected && !userExist) {
{'status': '200', 'msg': 'Successfully signed up user'})
} else {
callback('Error signing up user.', null)
function(error, results) {
console.log('error = ', error)
console.log('results = ', results)


Why am I experiencing this error:

**In getUserName.**
**In connectToDb.**
error = function () {
if (fn === null) throw new Error("Callback was already called.");
var callFn = fn;
fn = null;
callFn.apply(this, arguments);
results = undefined
**In checkIfUserExist.** undefined
callback(null, userExist);

TypeError: callback is not a function
at Timeout._onTimeout (/home/lem/js/async/asyncAuto.js:30:13)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)

Answer Source

There was a breaking change in async's auto method in v2, which you seem to use.

auto task functions now always take the callback as the last argument. If a task has dependencies, the results object will be passed as the first argument. To migrate old task functions, wrap them with _.flip

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download