2

I have a simple js file I'm executing with node script.js that does some async stuff.

However, the script exits before the callbacks execute. I read that node "waits until callbacks are ran before exiting." This doesn't seem to be the case - what am I doing wrong?

// script.js
asyncOp(function(err, result) { 
  console.log('callback'); // <- this doesn't happen 
}

Edit: Here is a concrete example. This is the entire script

// script.js
var User = require('../models/user'); // a mongoose model

User.create({name: "bob"}, function(err, user) { 
  console.log('callback'); // <- this doesn't happen 
};

I execute it with node script.js, but it exits before "callback" gets printed

4
  • Can you make a simple case (full script) that mirrors what you're trying to do, how you're trying to do it, and fails? Your question is a bit open ended as it is. Commented Jan 15, 2014 at 1:20
  • @PatrickGunderson added a concrete example. This is the entire script. Commented Jan 15, 2014 at 1:23
  • 2
    looks like you need to connect to the server for the create() method to be executed mongoosejs.com/docs/models.html Commented Jan 15, 2014 at 1:44
  • 1
    It's not a node issue but user error (forgot to open a db connection) Commented Jan 15, 2014 at 1:52

1 Answer 1

3

looks like you need to connect to the server for the create() method to be executed mongoosejs.com/docs/models.html

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

Comments

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.