I am trying to access Realtime Database using the new feature introduced with 3.1.0 release: "The Node.js SDK now supports unauthenticated access. If no service account is provided, Realtime Database access will be restricted just as any unauthenticated client would be."
The SDK is updated to 3.1.0:
user@ha:~/dev/project/auth/firebase$ sudo npm install -g firebase
[sudo] password for user:
var firebase = require('firebase');
console.log('Initialise Firebasse app');
// serviceAccount: "",
user@ha:~/dev/project/auth/firebase$ nodejs fb_anon.js
Initialise Firebasse app
throw new Error('Invalid service account provided');
What is happening is that your application is referring to an old sdk version that is inside your
node_modules. And thats because you updated the firebase sdk with the globally flag and you are referring to a local sdk.
You should be installing it locally to your application.
First make sure you added
"firebase":"3.1.0" into your
package.json file and then call
npm install inside the same dir.
I've just tested it with the same piece of code you added and everything went as expected.
In this question you can find some additional information and tips when using npm.