Andries Heylen Andries Heylen - 1 year ago 73
Node.js Question

I never get in the callback function, nodejs just stops

I always used nodejs together with express, but now I try to run the following script in nodejs (just by calling in the terminal "node myscript.js")

postModel is a mongoose model, doing a query on a mongodb.

'use strict'
var postModel = require(__dirname + '/../model/post').postModel;
function myfunction() {
console.log("before call");
.find({isArchived: false})
console.log("result is ok")

so what I don't understand is why I never see "result is ok" in my terminal.

I also tried this with the async and wait.for library, but also there my script just stops before the async function is executed and a result is returned.

I think I just miss something in what I am doing, but no idea what...

Answer Source

You need to call mongoose.connect() to actually connect to a database.

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