Create a boot script to run code at the start of a LoopBack API

Share this video with your friends

Send Tweet

In this lesson we will learn how to create a boot script.

We will use a boot script to create or update a predefined admin user, and give that user an Access Token. That way we don't have to log in to the API each time we want to use it as an authenticated user.

Front
Front
~ 7 years ago

Hi, tnx for great tutorial! I have one question, after I require bluebird I'm getting a new error:

Unhandled rejection TypeError: cb is not a function at /Projects/playground/egghead/loopback-tutorial/node_modules/loopback-boot/lib/executor.js:318:34 at tryCatcher (/Projects/playground/egghead/loopback-tutorial/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/Projects/playground/egghead/loopback-tutorial/node_modules/bluebird/js/release/promise.js:512:31) at Promise._settlePromise (/Projects/playground/egghead/loopback-tutorial/node_modules/bluebird/js/release/promise.js:569:18) at Promise._fulfillPromises (/Projects/playground/egghead/loopback-tutorial/node_modules/bluebird/js/release/promise.js:668:14) at Promise._settlePromises (/Projects/playground/egghead/loopback-tutorial/node_modules/bluebird/js/release/promise.js:694:18) at Async._drainQueue (/Projects/playground/egghead/loopback-tutorial/node_modules/bluebird/js/release/async.js:133:16) at Async._drainQueues (/Projects/playground/egghead/loopback-tutorial/node_modules/bluebird/js/release/async.js:143:10) at Immediate.Async.drainQueues (/Projects/playground/egghead/loopback-tutorial/node_modules/bluebird/js/release/async.js:17:14) at runCallback (timers.js:637:20) at tryOnImmediate (timers.js:610:5) at processImmediate [as _immediateCallback] (timers.js:582:5)

Somebody maybe know how to solve this? Tnx :)

Sergii Shvager
Sergii Shvager
~ 5 years ago

Hi, I've replaced .asCallback with regular .then and it worked. This way I don't need to require bluebird