Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Firebase Hosting to write a RESTful API in Node.js [duplicate]

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

like image 896
marco Avatar asked Feb 23 '17 12:02

marco


1 Answers

(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:

  • Node.js apps on Firebase Hosting Crash Course - Firecasts

and the documentation:

  • Cloud Functions for Firebase

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.

like image 186
rsp Avatar answered Sep 21 '22 22:09

rsp