function()

in app/api-service-broker/app.js [95:128]


      function(cb) {
        Hero.count({})
          .then(function(total) {
            console.log(`Heroes present: `, total);
            if (total === 0) {
              heroes = fs.readFileSync(`./data/heroes.json`, `utf8`);
              newHeroes = JSON.parse(
                heroes,
                (key, value) =>
                  key === `_id`
                    ? mongoose.Types.ObjectId.createFromHexString(value)
                    : value
              );
              Hero.create(newHeroes)
                .then(function(docs) {
                  console.log(`Inserted Heroes Count: `, docs.length);
                  return null;
                })
                .catch(function(err) {
                  console.log(`Error creating heroes: `, err);
                })
                .finally(function() {
                  return null;
                });
            }
            return null;
          })
          .catch(function(err) {
            console.log(err);
          })
          .finally(function() {
            cb(null);
          });
      },