Sunday, 16 April 2017

Javascript - get a parameter inside imbricated function

I'm just trying to make a little Web service with nodeJs (using ES6), and I have a little problem to get a parameter located outside a function i'm using. Hard to explain so this is my code :

    static InsertUser(user,callback){
    manager.Connect(manager => {
       var collection = manager.db.collection('Users');
        collection.insert(user
            , (err, result) =>{
                if(err)
                    throw err;
                callback(result);
            });
    })
}

When I want to call my callback (defined in the inserUser function, the server send me an error "callback is not a function". I guess the problem is that i'm inside another function so the server don't know what callback i'm talking about.

So here's my question, what the best way for me to call this callback in this situation?

thank you.



via Hadrien Delphin

No comments:

Post a Comment