Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

496
Views
Writing to Firebase database with node.js web server - "FIREBASE WARNING: set at ... failed: permission_denied"

I have a node.js web server, through which I am trying to write to Firebase. However, whenever it runs I get the following error message:

FIREBASE WARNING: set at /mydb failed: permission_denied 

Here is how I set up my application (relevant details):

var firebase = require('firebase');

var config = {
  apiKey: "8oc57xxx",
  authDomain: "example-04.firebaseapp.com",
  databaseURL: "https://example-ex04.firebaseio.com",
  projectId: "example-ex04",
  storageBucket: "example-ex04.appspot.com",
  messagingSenderId: "5022"
};

firebase.initializeApp(config);

function writeData(details) {
  firebase.database().ref('mydb/'). push({
    title: details.title,
    description: details.description,
    tags: details.tags
  }).then(function() {
    console.log('Upload succeeded');
  }).catch(function(error) {
    console.log('Upload failed');
  });;
}

Calling the function:

//what details looks like:
//{ title: 'Details',
  //description: 'Really fast, and awesome.',
  //tags: 'tag-1' 
//}

exports.postDetails = (req, res, next) => {
  writeData(req.body);

  const errors = req.validationErrors();

  if (errors) {
    req.flash('errors', errors);
    return res.redirect('/example');
  } 

  req.flash('success', { msg: 'Success!' });    
  res.redirect('/example');    
};

What do I need to do in order to get Firebase to accept my post? I have been reading over some docs on this:

https://firebase.google.com/docs/reference/js/firebase.database.Reference#set

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Have you finish your firebase sdk setting? You need to download a JSON file, and put it into your node server. Then initialize firebase with this code.

var admin = require("firebase-admin");

var serviceAccount = require("path/to/serviceAccountKey.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  apiKey: "8oc57xxx",
  authDomain: "example-04.firebaseapp.com",
  databaseURL: "https://example-ex04.firebaseio.com",
  projectId: "example-ex04",
  storageBucket: "example-ex04.appspot.com",
  messagingSenderId: "5022"
});

function writeData(details) {
  admin.database().ref('mydb/').push({
    title: details.title,
    description: details.description,
    tags: details.tags
  }).then(function() {
    console.log('Upload succeeded');
  }).catch(function(error) {
    console.log('Upload failed');
  });;
}

Calling the function:

//what details looks like:
//{ title: 'Details',
  //description: 'Really fast, and awesome.',
  //tags: 'tag-1' 
//}

exports.postDetails = (req, res, next) => {
  writeData(req.body);

  const errors = req.validationErrors();

  if (errors) {
    req.flash('errors', errors);
    return res.redirect('/example');
  } 

  req.flash('success', { msg: 'Success!' });    
  res.redirect('/example');    
};

You can check on this google site

Add the Firebase Admin SDK to your Server

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!