Skip to content

sseira/Node.js--server-firebase-cloudstorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js server hooked up to Firebase Database and Google Cloud Storage

Establish Connections (create .env file to store process variables):

Firebase:

    • Add Project
  1. Add Firebase to your app

	{ Example response
		<script>
		  // Initialize Firebase
		  var config = {
		    apiKey: "xxxxxx",
		    authDomain: "xxxxxx.firebaseapp.com",
		    databaseURL: "https://xxxxxx.firebaseio.com",
		    projectId: "xxxxxx",
		    storageBucket: "xxxxxx.appspot.com",
		    messagingSenderId: "xxxxxx"
		  };
		  firebase.initializeApp(config);
		</script>
	}
  1. Add apiKey, authDomain, databaseURL, projectId, and storageBucket in .env file

Google Cloud Storage

  1. Setup public access to your Firebase database & Storage

    • firebase console -> Database tab -> Rules tab
    • rules:
    	{
    	  "rules": {
    	    ".read": "auth == null",
    	  	".write": "auth == null"
    	  }
    	}
    • firebase console -> Storage tab -> Rules tab
    • rules:
    	service firebase.storage {
    	  match /b/{bucket}/o {
    	    match /{allPaths=**} {
    	      allow read, write;
    	    }
    	  }
    	}
  2. Create a Cloud Storage project by using the drop down on the top left next to Google Cloud Platform logo

  3. Click on the Credentials tab, create a new credential file

    • Service account key

      • Service account: App Engine default service account
      • Key type: JSON
    • Your private key .json file should automatically download

  4. Rename and store private key file as private_key.json file in the server's main directory, ADD TO .gitignore!!

  5. Add private_key.json filename as STORAGE_KEY_FILENAME into .env file

Running Locally

$ npm install
$ nodemon ./server.js localhost 5000
$ npm start

About

Node.js server hooked up to firebase and google cloud storage

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published