【发布时间】:2018-08-28 22:58:03
【问题描述】:
我正在尝试创建 Node Js 服务器,在该服务器中调用特定的 rest api 它将更改 firebase 中的一些数据。
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var admin = require("firebase");
admin.initializeApp({
serviceAccount: './<some-name>nsdk-dgimw-1cab1079fa.json',
databaseURL: "https://<some-name>.firebaseio.com"
});
// define a simple route
app.get('/', function(req, res){
res.json({"message": "Welcome to EasyNotes application. Take notes quickly. Organize and keep track of all your notes."});
});
app.get('/getMe', function(req, res){
var ref = admin.database().ref();
var childBlog = ref.child('/bloggers');
// var userRef = childBlog.push();
var userRef = childBlog.push({
name: 'Christopher',
description: 'I eat too much ice cream'
});
console.log('user key', userRef.key);
var myInt = setTimeout(function () {
console.log("Hello");
}, 10000);
});
// listen for requests
app.listen(3000, function(){
console.log("Server is listening on port 3000");
});
这段特定的代码正在创建一个服务器,并且 rest api 调用工作正常。但是当我插入 firebase 推送代码时,它会记录生成的推送密钥,但是当我访问 firebase 数据库时,我发现没有任何变化。
我关注了这个article
我想知道我做的事情是否正确,如果不正确,正确的解决方案是什么?
数据库结构--
-tech-bloggie
-articles
-bloggers
-comments
Warning :
@firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"getaddrinfo ENOTFOUND accounts.google.com accounts.google.com:443\"."}
【问题讨论】:
-
你的数据库有
/bloggers子吗? -
@ShababbKarim 是的,我在数据库中有博客作者作为孩子
标签: node.js angular firebase firebase-realtime-database