Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to host nodeJS project to firebase?

I am using node, express and more other dependencies for the project. I wonder how to host this project on firebase. My project will have controller, view , and any other folders to make the project possible.It already has view engine like pug/handlebars.

Tutorials online only show how to host firebase with single index.html in public folder. How am I suppose to host my project with all other folders? I know how to use firebase in nodeJS, but how to host the project on firebase? How firebase will access the server file(either app/index.js)? Where should I put all these folders?

Hopefully I am not asking to much. If my question isn't clear, please let me know so that I can make clarification.

like image 506
jiancheng wu Avatar asked Aug 06 '17 22:08

jiancheng wu


People also ask

Can I deploy node JS project on Firebase?

You'll need a Node. js environment to write functions, and you'll need the Firebase CLI to deploy functions to the Cloud Functions runtime. For installing Node. js and npm, Node Version Manager is recommended.

How do I host a node site on Firebase?

Create a Firebase project First you need to create a project on the Firebase website. Proceed to click on Create a project. Enter a project name and check yes if you wish to add analytics to your project. Wait for the project to be created.

Can you run a node server on Firebase?

Introducing Firebase Hosting. Not only do you get free static website hosting, you are able to host a Node server practically for free. This assumes that you have the Firebase CLI installed and that you have an account setup on Firebase, if not, you can follow this to create a profile and this to get the CLI setup.


2 Answers

You're in luck. Firebase just this week released a video that walks step-by-step through setting up an Node.js/Express app on Firebase Hosting.

This has only been possible since the integration of Cloud Functions with Firebase Hosting, which was released at I/O 2017. Most tutorials likely are from before that time, when there was no way to run server-side code on Firebase Hosting.

like image 182
Frank van Puffelen Avatar answered Sep 22 '22 17:09

Frank van Puffelen


You can do this by firebase cloud function. Deployment auth is handled by the Firebase CLI, so getting a hello world up and running is literally:

firebase init functions firebase deploy 

A simple hello world function

functions.https.onRequest((request, response) => {     response.send(“Hello from Firebase!”); }); 

Note: You can use express with firebase function.

For more follow documentation link: https://firebase.google.com/docs/functions

like image 37
Sunny Sultan Avatar answered Sep 19 '22 17:09

Sunny Sultan