-1

So I am trying using a package called "app-store-scraper"

All of the examples look something like this:

var store = require('app-store-scraper');

store.app({id: 553834731}).then(console.log).catch(console.log);

but all it does is print it to the console. So I was wondering how to put it into a variable?

I have tried to do var test = store.app({id: 553834731}) but it returns nothing

Edit: I'm using this to return like res.end(); on a webserver. so I'm trying to return store.app()

oredgaming
  • 11
  • 2

2 Answers2

0

Your function - store.app() returns a promise.

you can do:

var test = store.app({id: 553834731})
test.then(console.log);

in a modern async/await syntax, which is a lot easier to understand, your code can be rewritten:

try {
  const ret = await store.app({id: 553834731});
  console.log(ret);
}
catch (e) {
  console.log(e);
}
Igor Shmukler
  • 1,742
  • 3
  • 15
  • 48
  • I'm using this to return like ```res.end();``` on a webserver. and I'm very new to javascript so i dont know how async works. So to clairfy: how do i return the ```store.app()``` – oredgaming Sep 27 '21 at 14:54
0
let result;

store.app({ id: 553834731 }).then(res => result = res).catch(console.error);

or

const result = await store.app({ id: 553834731 });
SharedRory
  • 246
  • 6
  • 17