CategoryModel.find, gathers all records inside a db. Error if something goes wrong and categories is my output array.
categoryModel.find(function(error, categories) {
  if(error){
    console.log(error)
  }
});
I need to reach that categories outside of the function.
var result = categoryModel.find(function(error, categories) {
  if(error){
    console.log(error)
  }
  console.log(categories)
});
console.log(result.categories)
This type is not working. Im beginner at javascript :( Thanks
SOLVED
var result = {}
categoryModel.find(function(err, categories) {
  console.log(categories)
  result = categories
  callback(result)
});
console.log(result)
 
     
    