14

Let's take for example the server.js Hello World

  var http = require("http");
  http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.end("Hello World");
  }).listen(80);

How can I use it in Firebase ?

Sorry for the duplicate but the answers were 3yo

marco
  • 3,193
  • 4
  • 28
  • 51

1 Answers1

22

(Update: Now the answer is: Yes, you can - see updates below)

Original answer

No, you can't. Firebase hosting is only for static content.

See: https://firebase.google.com/docs/hosting/

Firebase Hosting provides fast and secure static hosting for your web app.

You need either a service like Heroku that can run your Node app, or you need your own server where you will install Node and run your app.

Update

Now you can host your Node apps on Firebase directly - thanks to Ayyappa for pointing it out in the comments.

See this excellent video tutorial:

and the documentation:

Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.

Note that this is still in Beta:

This is a Beta release of Google Cloud Functions. This API might be changed in backward-incompatible ways and is not subject to any SLA or deprecation policy.

rsp
  • 107,747
  • 29
  • 201
  • 177