Now the error you're getting is permission related. To solve this, follow the steps below :
1) Go to the console of your firebase project.
2) Select 'Database' from the sidebar.
3) Then choose 'Realtime Database'.
4) Go to 'rules' tab,
5) Then, write : true, read : true.
6) Do save and check the code again.
It should work now!