Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
How can I merge this function together

Now I have this code to create sitemap.xml when I run /sitemap.xml

 database = firebase.database();
    var ref = database.ref('urls');
    ref.on('value', gotData, errData);

    function errData(err){
        console.log('Error!');
        console.log(err);
    }  


function gotData(data){
        result = data.val() 
        return urls = Object.keys(result)
                     .filter(key => result[key].last_res > 5)
                     .map(key => ({url: '/' + result[key].url_site + '/'}))
    }

when i try running console.log(urls) in gotData(data) function, it returns as

{ salmon: 
   { count: 1,
     last_res: 10,
     url_site: 'salmon' },
  'salmon-food': 
   { count: 1,
     last_res: 601,
     url_site: 'salmon-food' } }

I need to merge this code to above function

var sitemap = sm.createSitemap({ 
            hostname: 'xxx.com',
            cacheTime: 600000,
            urls: urls

        });
app.get('/sitemap.xml', function(req, res) {
    sitemap.toXML( function (err, xml) {
        if (err) {
            return res.status(500).end();
        }
        res.header('Content-Type', 'application/xml');
        res.send( xml );
    });
    });
}

I need to return urls in gotData(data) to create sitemap.xml. So how can I merge this code together

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Many pieces of code are missed, but common approach would be something like:

function gotData (data) {
    const result = data.val();
    const urls = Object.keys(result)
        .filter(key => result[key].last_res > 5)
        .map(key => ({url: 's/price/' + result[key].url_site + '/'}));

    const sitemap = sm.createSitemap({     // supposing it is sync...
        hostname: 'xxx.com',
        cacheTime: 600000,
        urls
    });

    return sitemap;
}

app.get('/sitemap.xml', (req, res) => {
    const siteMap = gotData(data???);
    sitemap.toXML(siteMap, (err, xml) => {
        if (err) return res.status(500).end();

        res.header('Content-Type', 'application/xml');
        return res.send( xml );
    });
});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!