Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

491
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda