I
I
Ilya Loopashko2020-09-01 05:00:44
Node.js
Ilya Loopashko, 2020-09-01 05:00:44

How to transfer data from console.log to json file?

There is a script that outputs data to console.log, how to put data from console.log into a separate json file?

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

store.search({
  term: 'ninja',
  num: 2,
  page: 3,
  country : 'us',
  lang: 'lang'
})
.then(console.log)
.catch(console.log);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Loopashko, 2020-09-01
@deadloop

Here is a solution:

const fs = require('fs');
const store = require('app-store-scraper');

store.search({
    term: 'ninja',
    num: 2,
    page: 3,
    country : 'us',
    lang: 'lang'
})
    .then(response => {
        fs.writeFileSync('file.json', JSON.stringify(response));
    })
    .catch(err => {
        fs.writeFileSync('file.json', JSON.stringify(err));
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question