0
APIサーバーにhttps.requestを作成しようとしています。チャンク(JSON)を受け取ってコンソールに表示することができます。どうすればHTMLに直接書き込んでブラウザに表示できますか?本文HTMLのJSONリクエスト
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);
JSONをストリング化する必要があります –