Sunday, 2 April 2017

How to start a server with NodeJS and Firebase?

I have an old Firebase app which uses AngularJS (with routes). I'm trying to use/add the Firebase Admin SDK which requires Nodejs. I have never used Nodejs before. I run 'node firebasedb.js'. firebasedb.js contains this code:

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

var serviceAccount = require("./myServiceAccount.json");

// Initialize Firebase
var config = {
   credential: firebase.credential.cert(serviceAccount),
   apiKey: "<api key>",
   authDomain: "<authdomain>",
   databaseURL: "<database url>",
   storageBucket: "<storage bucket>",
};

firebase.initializeApp(config);

How do I start a server? Right now I use Brackets which has a built in web server, I needed a server so that the AngularJS routeProvider works but now I'm trying to integrate the Firebase Admin which requires Nodejs. I can't use the server of Brackets anymore since the console will say require is not defined.

Some follow-up questions: When I deploy my Firebase app, do I still use firebase deploy? What happens to my node modules when I do that? Will Node still work? Does the server of Firebase (when I deploy) become the server of Node? I don't understand.



via Zik

No comments:

Post a Comment