I have fetched a text doc from an url and stored in the response.
I want to do 3 things here:-
- Find count of words from the doc.
- Collect details for top 3 words (order by word occurrences) and show synonyms and part of speech.
API :- https://dictionary.yandex.net/api/v1/dicservice.json/lookup Key :- something..
- Show above top 3 word list results in json format
All should be in asynchronous way.
const fetch = require("node-fetch");
async function fetchTest() {
    let response = await
    fetch('http://norvig.com/big.txt')
        .then(response => response.text())
        .then((response) => {
            console.log(response)
        })
        .catch(err => console.log(err));
}
(async() => {
    await fetchTest();
})();
EDIT:-
const fetch = require("node-fetch");
async function fetchTest(responses) {
    let response = await
    fetch('http://norvig.com/big.txt')
        .then(response => response.text())
        .then((response) => {
            console.log(response); // ------------------> read text  from doc
            var words = response.split(/[ \.\?!,\*'"]+/);
            console.log(words);
                
               var array = Object.keys(words).map(function(key) {
                return { text: words[key], size: key };
                });
                console.log(array); //-----------------------> occurence count of words
                   var sortedKeys =  array.sort(function (a, b) {
                    return  b.size - a.size ;
                    });
                    var newarr = sortedKeys.slice(0, 10);
                    console.log(newarr); // --------------> top 10 text and occurence
                    var permittedValues = newarr.map(value => value.text);
                    console.log(permittedValues); //---------------> sorted key in array
                    fetch('https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key=domething_&lang=en-en&text=in&callback=myCallback')
                        .then(responses => responses.text())
                        .catch(err => console.error(err));
                        console.log(this.responses);
                                             
                       
         })
        .catch(err => console.log(err));
}
(async() => {
    await fetchTest();
})();
Unable to do fetch API with json response to show synonyms and part of speech. Where am I going wrong ?
 
    