Sometimes when I’m doing the Node.js lessons, I don’t really understand what’s happening and I’d like to console.log the data variable to see what’s going on.
For example, this is the answer I got for ‘Create and Save a Record of a Model’ lesson:
console.log ("Hello World!");
var createAndSavePerson = function(done) {
var newPerson = new Person ({name: 'Bobby', age: 42, favoriteFoods: ['Tacos', 'Pizza', 'Pickles']});
newPerson.save(function(err, data) {
console.log(data);
if (err) return done(err)
return done(null, data);
});
}
I put 2 console.log commands to see if it worked. The first one returns “Hello World!” in the Glitch Status Logger. The second one, nothing happens.
Is it because the createAndSavePerson is a function? It’s not actually being called, so the code inside the function isn’t actually running just yet? Or am I missing something.