14

So I have this web-app using angularJS and nodeJS. I don't want to just use localhost to demo my project because it doesn't looks cool at all when I type "node server.js" and then go to localhost.....

Since I intend to use Firebase for the data, I have noticed that Firebase provides hosting. I tried it, but it seems to only host the index.html and not through/using server.js. I have customized files for the server to use/update. So, how can I tell Firebase Hosting to use my server and related files when hosting?

Is it possible to tell Firebase, hey, run "node server.js" to host my index.html?

3
  • 6
    Firebase Hosting can only host static files. It will not execute your node.js (or any other) code. But if you current server.js is just serving static files, then you can just upload those to Firebase Hosting and it will work fine. If your server.js does more and you're looking where to host this node.js code, there are a multitude of options a google search away (asking for such recommendations is off-topic for StackOverflow, since there are likely to be as many preferences as there are SO users). Commented Oct 29, 2014 at 18:20
  • 1
    Since you don't want to use localhost/your_project because "it doesn't look cool", consider modifying the hosts file in your computer so as to make any domain (even google.com) point at your localhost. Obviously this trick will work only as long as you are viewing the website from your computer. winks Commented Nov 2, 2016 at 14:03
  • It's now possible to host node apps - See answer to this "Duplicate" question with more up-to-date details: stackoverflow.com/questions/42415677/… Commented Oct 17, 2017 at 11:10

3 Answers 3

11

I'm guessing by the way you are wording the question you want to see this site from "the internet".

Two routes you could go here.

a) Serve your index through Firebase hosting. Firebase only hosts assets. If your Angular app is being served through Node then you will need to change your architecture to be more SPA-ish

SPA-ish would be like an index bootstrap that interacts with the backend purely through API's.

You would host the API server on something more appropriate like through Nodejitsu.

b) Serve the whole thing through something like Nodejitsu (hosting platform) or your very own VM managed by a different kind of hosting company like BuyVM.net.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Yea my last app was purely SPA-ish. That is why I want to get more involved with server stuff. I will try out some nodeJS hosting things. Thanks for the quick response :)
See answer to this "Duplicate" question with more up-to-date details: stackoverflow.com/questions/42415677/…
5

Another idea, is if your nodejs app is independent of the angularjs app (however they use shared data, and perform operations on that data model) you could separate the two and connect them only via firebase.

Firebase hosting -> index.html and necessary angularjs files.

Locally (your PC) -> server.js which just connects to firebase and trigger on changed data.

I have done this for a few projects and it's a handy way to access the outside world (internet) while maintaining some semblence of security by not opening ports blindly.

I was able to do this to control a chromecast at my house while at a friends house

Here's an example from my most recent project (I'm trying to make a DVR).

https://github.com/onaclov2000/webdvr/blob/master/app.js

var FB_URL = '';
var Firebase = require('firebase');

var os = require('os')
var myRootRef = new Firebase(FB_URL);

var interfaces = os.networkInterfaces();
var addresses = [];
for (k in interfaces) {
    for (k2 in interfaces[k]) {
        var address = interfaces[k][k2];
        if (address.family == 'IPv4' && !address.internal) {
            addresses.push(address.address)
        }
    }
}

// Push my IP to firebase
// Perhaps a common "devices" location would be handy
var ipRef = myRootRef.push({
    "type": "local",
    "ip": addresses[0]
});


myRootRef.on('child_changed', function(childSnapshot, prevChildName) {
   // code to handle child data changes.
   var data = childSnapshot.val();
   var localref = childSnapshot.ref();
   if (data["commanded"] == "new") {
      console.log("New Schedule Added");
      var schedule = require('node-schedule');
      var date = new Date(data["year"], data["month"], data["day"], data["hh"], data["mm"], 0);
      console.log(date);
      var j = schedule.scheduleJob(date, function(channel, program, length){
                 console.log("Recording Channel " + channel + " and program " + program + " for " + length + "ms");
      }.bind(null, data["channel"], data["program"], data["length"]));

      localref.update({"commanded" : "waiting"});
  }
});

When I change my "commanded" data at the FB_URL, to "new" (which can be accomplished by angularjs VERY Simply, using an ng-click operation for example) it'll schedule a recording for a particular date and time (not all actually functional at the moment).

Comments

2

I might be late but since 3 years have passed there is an solution available now from Firebase in the form of cloud functions Its not straight forward but looks promising if one can refactor their code a bit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.