Ich versuche eine https.request zu einem API-Server zu machen. Ich kann den Chunk (JSON) empfangen und in der Konsole ausdrucken. Wie kann ich es direkt in HTML schreiben und im Browser anzeigen?JSON Anfrage in body html
var requestListener = function (req, res) {
var db = admin.database();
var ref = db.ref("Clubs");
ref.on("value", function(snapshot) {
console.log(snapshot.val()); //print on console
res.write(snapshot.val()); // in body html, error throw er;
// Unhandled 'error' event ^Error: write after end
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
// CRUD
ref.child("club1").set({
clubId: 1,
clubName: "club1",
telephone: "6548798",
address: "Lviv",
party: "qwe,asd,zxc"
});
ref.child("club2").set({
clubId: 2,
clubName: "club2",
telephone: "234234",
address: "Kiev",
party: "qwe,zxc"
});
res.end();
};
var server = http.createServer(requestListener);
server.listen(8080);
Sie müssen den JSON stringieren –