Saturday, 27 May 2017

How to append two results of query in one json in Node.js

Following is my code of in node.js i would like to know how to append two results of query in one json and send the json in response.

    router.get("/get-meta", function(req, res, next){
    connection.query("select id, country_name from country", function (error, results) {

        if (error) res.json({"status": "failed", "message": error.message});
        else results = (JSON.stringify({ results }));
    });
    connection.query("select id, currency from currency", function (error, results2) {

        if (error) res.json({"status": "failed", "message": error.message});
        else res.send(JSON.stringify({ results2 }));
    });
});



via Azeem Ullah

No comments:

Post a Comment