我已经成功运行了Firebase模拟器:
E:firebase>firebase emulators:start
i emulators: Starting emulators: functions, firestore
! Your requested "node" version "8" doesn't match your global version "10"
+ functions: Emulator started at http://localhost:5001
! No Firestore rules file specified in firebase.json, using default rules.
i firestore: Serving ALL traffic (including WebChannel) on http://localhost:808
0
! firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and
will go away soon. Please use port above instead.
i firestore: Emulator logging to firestore-debug.log
+ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i functions: Watching "E:firebasefunc
tions" for Cloud Functions...
! functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to
E:firebasekey.json. Non-emulated serv
ices will access production using these credentials. Be careful!
+ functions[notifyNewMessage]: firestore function initialized.
+ All emulators started, it is now safe to connect.
具有notifyNewMessage
函数的functions
文件如下:
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp()
exports.notifyNewMessage = functions.firestore
.document('test/{test}')
.onCreate((docSnapshot, context) => {
console.log(docSnapshot.data())
}
当我在 Firebase 控制台中手动创建新文档时,Windows 中的 CLI 不会记录任何内容。如何解决此问题,以便它记录函数在我的 CLI 中所说的内容?
我只是个白痴,没有通过代码重新编译。
本地模拟器不会响应 Firestore 数据库中的更改,该数据库托管在 Google 的云中并在控制台中可见。 它响应的是本地模拟的 Firestore 数据库中的更改,该数据库也在您的计算机上运行。 如果您希望在本地模拟器中触发 Firestore 函数,则必须改为对模拟的 Firestore 进行更改,如文档中所述。 你可能想要完成提供的快速入门,以获得这方面的一些经验。
如果您不想使用 Firestore 模拟器,只想直接触发它进行测试,则可以使用 Firebase CLI 本地外壳。