0

I have 3 classes and data in country.json

country.json

[{"country":"Algeria","region":"Northern Africa","code":"DZ","population":41318142,"cities":["Boumerdas","Zeribet el Oued","Zeralda"]},{"country":"American Samoa","region":"Polynesia","code":"AS","population":55641,"cities":["Aūa","Vaitogi","Vailoatai"]}

in countryRep class I make this funnction to get the sum of population

   async  getSumAllPopulation(){
            let countries = await this.getCountries();
           let populations= countries.map(s=>s.population).reduce((acc, s) => s + acc);
           return populations;
        }

in test I write

app.get('/PopulationSum', async (req, res) => {
    const countries = await repo.getSumAllPopulation();
    res.send(countries);
})

getCountries() function

    async getCountries() {
        try {
            const countries = await fs.readJSON(this.countryFilePath);
            return countries;
        }
        catch (e) {
            console.log(e)
        }

    }

But I didn't get the result of the sum ? How I can fix it? I got an error it seems the method didn't return any thing.

enter image description here

0 Answers0