Saturday, 4 August 2018

Callback in Node.js When Using JavaScript Function

I am trying to run two codes that place an "id" into the "posts" array. As the two codes should be non-blocking, I tried to use callback to run the codes. They are as follow:posts.unshift(post1._id, function(posts){ posts.unshift(post2._id); }); When I tried to run the code, Node.js says that "Cast to ObjectId failed for value "[Function]" at path 'posts'". Node.js crashes after running the first part of code. I am not sure where goes wrong. Is it because 'unshift' is not an I/O operation, and therefore can't use callback as 'unshift' is still being ran in Node.js?

Submitted August 04, 2018 at 08:33AM by VickNicks

No comments:

Post a Comment