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

216
Vistas
firebase is not defined (using version 9.6.7)

Am I using outdated code? Also, I set the rules of the database so read and write are true. That makes the database changeable from any device. When I try searching on stack overflow, firebase is not defined, I get irrelevant answers.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="module">
        // Import the functions you need from the SDKs you need
        import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-app.js";
        import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-analytics.js";
        import { getDatabase } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-database.js";
        // TODO: Add SDKs for Firebase products that you want to use
        // https://firebase.google.com/docs/web/setup#available-libraries
      
        // Your web app's Firebase configuration
        // For Firebase JS SDK v7.20.0 and later, measurementId is optional
        const firebaseConfig = {
          apiKey: "AIzaSyCnfB3Tfu9bo7PyEvhB1ZAPBbit7ZWm9D8",
          authDomain: "square-1cdce.firebaseapp.com",
          projectId: "square-1cdce",
          storageBucket: "square-1cdce.appspot.com",
          messagingSenderId: "82191280296",
          appId: "1:82191280296:web:45e62faffbb7e8a94cfa9d",
          measurementId: "G-NT53HS3WE9"
        };
      
        // Initialize Firebase
        const app = initializeApp(firebaseConfig);
        const analytics = getAnalytics(app);
        </script>
        <script>
        const db = firebase.database()
        db.ref("users/").set({
            user:"hello"
        });
      </script>
</body>
</html>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have to use the getDatabase function you imported here:

import { getDatabase } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-database.js";

So, you can do const db = getDatabase(), and access your realtime using that.

Your snippet with the fix:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="module">
        // Import the functions you need from the SDKs you need
        import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-app.js";
        import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-analytics.js";
        import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-database.js";
        // TODO: Add SDKs for Firebase products that you want to use
        // https://firebase.google.com/docs/web/setup#available-libraries
      
        // Your web app's Firebase configuration
        // For Firebase JS SDK v7.20.0 and later, measurementId is optional
        const firebaseConfig = {
          apiKey: "AIzaSyCnfB3Tfu9bo7PyEvhB1ZAPBbit7ZWm9D8",
          authDomain: "square-1cdce.firebaseapp.com",
          projectId: "square-1cdce",
          storageBucket: "square-1cdce.appspot.com",
          messagingSenderId: "82191280296",
          appId: "1:82191280296:web:45e62faffbb7e8a94cfa9d",
          measurementId: "G-NT53HS3WE9"
        };
      
        // Initialize Firebase
        const app = initializeApp(firebaseConfig);
        const analytics = getAnalytics(app);
        const db = getDatabase()
        set(ref(db, 'users/'), {
          hello: 'world'
        });

        </script>
</body>
</html>

You probably won't be able to do this inside StackOverflow snippets because it runs in an iFrame

You can also refer to the docs here: https://firebase.google.com/docs/database/web/read-and-write

about 4 years ago · Juan Pablo Isaza 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