Node - ReferenceError: promise not defined

I start with Node. Sorry for what is probably a stupid question.

Trying to understand why the code below causes an error: ReferenceError: Promise not defined

allAccountFixtures: ['account-customer-joe', 'account-partner-sam', 'account-partner-jane', 'account-admin-jill'],
allProductFixtures: ['product-123', 'product-234', 'product-345', 'product-456'],
...
loadBasicFixtures: (Api) => {
    return Promise.all([
      Support.importRecords(Api.accountsAPI, Support.allAccountFixtures),
      Support.importRecords(Api.productsAPI, Support.allProductFixtures)
   ]);
},

My APIs are defined elsewhere:

this.accountsAPI = app.service('/api/accounts');
this.productsAPI = app.service('/api/products');

Import function:

importRecords: (feathersService, fixtureNames) => {
    // Wrap in an array if there only one.
    if (!(fixtureNames instanceof Array)) { fixtureNames = [fixtureNames]; }

    // Create a separate promise for each JSON fixture to load the JSON from a
    // file and send it to feathers.create(). Don't execute yet.
    var promises = fixtureNames.map(fixtureName => {
      var filePath = `test/fixtures/json/${fixtureName}.json`;
      // console.log(`-> Loading JSON fixture: ${filePath}`);

      return fs.readFileAsync(filePath, 'utf8')
        .then((jsonString) => {
        return JSON.parse(jsonString);
      }).then((json) => {
        return feathersService.create(json);
      });
    });

    // Wrap all fixture loading promises inside a single outer promise that will
    // fire when all of the child promises are complete.
    return Promise.all(promises);
},

I do not know if the information provided is enough to tell what is happening. I took a look at the concept of "promise" and that is pretty much. Perhaps you could point in the right direction. The documentation mentions permission and rejection.

+4
source share
2 answers

I will make my comment in response, as it solved your problem.

node.js promises promises , .

4.x node.js , promises node.js.

+5

Promise

npm install promise --save

var Promise = require('promise');
+1

Source: https://habr.com/ru/post/1618716/


All Articles