Accessing Firebase in Node.JS/express globally
<p>In my main express file, <code>app.js</code>, I set up Firebase:</p>

<pre><code>var firebase = require("firebase");
firebase.initializeApp({
  serviceAccount: "../Wrapper-adfd67bc8c36.json",
  databaseURL: "https://wrapper.firebaseio.com"
}); 
</code></pre>

<p>But when I try to access it in a routing file: </p>

<pre><code>var express = require('express');
var router = express.Router();

router.get('/:id', function(req, res, next) {
    functionThatUsesFirebase(req.params.id);

    res.send(req.params.id);
});
</code></pre>

<p>I get the error:</p>

<pre><code>firebase is not defined.
</code></pre>

<p>So then I tried just adding Firebase to the routing file itself:</p>

<pre><code>var express = require('express');
var router = express.Router();
var firebase = require("firebase");
firebase.initializeApp({
  serviceAccount: "../Wrapper-adfd67bc8c36.json",
  databaseURL: "https://wrapper.firebaseio.com"
});

router.get('/:id', function(req, res, next) {
    functionThatUsesFirebase(req.params.id);

    res.send(req.params.id);
});
</code></pre>

<p>I get the console error: </p>

<pre><code>Firebase App named '[DEFAULT]' already exists.
</code></pre>

<p>How can I make Firebase accessible to all of my routing files? Thanks!</p>