{"id":30199855,"url":"https://github.com/codingwithmanny/firebase-nodejs","last_synced_at":"2025-08-13T08:42:53.921Z","repository":{"id":38805892,"uuid":"194996128","full_name":"codingwithmanny/firebase-nodejs","owner":"codingwithmanny","description":"Sample Firebase NodeJS React","archived":false,"fork":false,"pushed_at":"2022-12-10T21:12:42.000Z","size":771,"stargazers_count":1,"open_issues_count":18,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-04T06:55:48.491Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codingwithmanny.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-03T06:49:23.000Z","updated_at":"2025-02-05T22:07:10.000Z","dependencies_parsed_at":"2022-09-18T10:32:14.646Z","dependency_job_id":null,"html_url":"https://github.com/codingwithmanny/firebase-nodejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codingwithmanny/firebase-nodejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingwithmanny%2Ffirebase-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingwithmanny%2Ffirebase-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingwithmanny%2Ffirebase-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingwithmanny%2Ffirebase-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codingwithmanny","download_url":"https://codeload.github.com/codingwithmanny/firebase-nodejs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingwithmanny%2Ffirebase-nodejs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270212253,"owners_count":24546101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-13T08:42:32.387Z","updated_at":"2025-08-13T08:42:53.901Z","avatar_url":"https://github.com/codingwithmanny.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Firebase NodeJS\n\n# Requirements\n\n- NVM\n- NodeJS 8.16.0\n- Firebase Tools\n\n## Local Setup\n\n### Node Version\n\nMake sure you have the correct version of node installed because firebase only supports specific versions of node and not the latest versions.\n\n```bash\nnvm install;\n```\n\n### Firebase Tools\n\nMake sure you have the firebase tools installed on your computer with the correct node version.\n\n```bash\nyarn add firebase-tools; # npm install firebase-tools\n```\n\n### Initial Firebase Setup From Scratch\n\nThese are the steps you would take if you were setting your project from scratch. If the project is already setup, please ignore these steps and proceed to `### Existing Firebase Setup`\n\n1. Make sure you are logged into your google account:\n\n```bash\n./node_modules/firebase-tools/lib/bin/firebase.js login;\n```\n\n2. Init or select your project\n\n```bash\n./node_modules/firebase-tools/lib/bin/firebase.js init;\n```\n\n3. When the prompt appears, select `Functions`\n\n```\nWhich Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter\n to confirm your choices.\n ◯ Database: Deploy Firebase Realtime Database Rules\n ◯ Firestore: Deploy rules and create indexes for Firestore\n❯◉ Functions: Configure and deploy Cloud Functions\n ◯ Hosting: Configure and deploy Firebase Hosting sites\n ◯ Storage: Deploy Cloud Storage security rules\n```\n\n4. You'll need to select an existing project:\n\n```\nSelect a default Firebase project for this directory:\n  [don't setup a default project]\n❯ yourproject (your-project)\n  [create a new project]\n```\n\n5. Select `JavasScript` for this tutorial:\n\n```\nWhat language would you like to use to write Cloud Functions? (Use arrow keys)\n❯ JavaScript\n  TypeScript\n```\n\n6. Enable `ESLint`:\n\n```\nDo you want to use ESLint to catch probable bugs and enforce style? (y/N) y\n```\n\n7. Install dependencies:\n\n```\nDo you want to install dependencies with npm now? (Y/n) y\n```\n\n8. Adding Service Account Key:\n\n**_NOTE_:** Make you sure only perform this step once and just refer to the existing generated file otherwise every time you generate a new key, every one else's code will **NOT WORK**.\n\nA. In your firebase console in the browser, next to `Project Overview`, click the `⚙` icon and go to `Project Settings`.\n\nB. In the top navigation, go to `Service Accounts`\n\nC. Under `Firebase Admin SDK`, make sure `Node.js` is selected and click **Generate new private key**\n\nD. Place the downloaded file and rename it as `functions/config/serviceAccountKey.json`\n\n9. Adding Config File:\n\nA. In your firebase console in the browser, next to `Project Overview`, click the `⚙` icon and go to `Project Settings`.\n\nB. In the top navigation, go to `General`\n\nC. Scroll down to section `Your Apps` \u003e `Web apps` and make sure your project is selected.\n\nD. Under `Firebase SDK snippet` make sure `Config` is selected and copy the scripts:\n\n```javascript\nconst firebaseConfig = {\n  apiKey: '{api-key}',\n  authDomain: '{auth-domain}',\n  databaseURL: '{database-url}',\n  projectId: '{project-id}',\n  storageBucket: '{storage-bucket}',\n  messagingSenderId: '{messaging-sender-id}',\n  appId: '{app-id}'\n};\n```\n\nE. Create a new file called `functions/config/config.json`, paste and modify the code as:\n\n```json\n{\n  \"apiKey\": \"{api-key}\",\n  \"authDomain\": \"{auth-domain}\",\n  \"databaseURL\": \"{database-url}\",\n  \"projectId\": \"{project-id}\",\n  \"storageBucket\": \"{storage-bucket}\",\n  \"messagingSenderId\": \"{messaging-sender-id}\",\n  \"appId\": \"{app-id}\"\n}\n```\n\n### Existing Firebase Setup\n\n1. Configure `.firebaserc`\n\n```bash\ncp .firebaserc.example .firebaserc;\n```\n\n2. Make sure you are logged into your google account:\n\n```bash\n./node_modules/firebase-tools/lib/bin/firebase.js login;\n```\n\n3. Set project\n\n```json\n{\n  \"projects\": {\n    \"default\": \"your-project\"\n  }\n}\n```\n\n4. Configure your `config.json` file:\n\nCopy and modify accordingly with the right crentials.\n\n```bash\ncp functions/config/config.example.json functions/config/config.json;\n```\n\n5. Configure your `serviceAccountKey.json` file:\n\nCopy and modify accordingly with the right crentials.\n\n```bash\ncp functions/config/serviceAccountKey.example.json functions/serviceAccountKey/config.json;\n```\n\n_*NOTE*:_ If you get the following error, make sure to do `nvm install` in the root to install the correct node version:\n\n```bash\nerror functions@: The engine \"node\" is incompatible with this module. Expected version \"8\". Got \"10.15.3\"\nerror Found incompatible module.\n```\n\n6. Install Root Dependencies\n\n```bash\nyarn install; # npm install\n```\n\n7. Install Functions Dependencies\n\n```bash\ncd functions;\nyarn install; # npm install\n```\n\n## Creating Local Server Start\n\nFirebase by default uploads the code to be compiled on Google's servers, which takes time. There is a way around this, where we'll add a local development script in our `package.json`:\n\nAdd the following: `\"local-start\": \"PORT=5000 node src/index.js\",`\n\n`functions/package.json`\n\n```json\n  \"scripts\": {\n    \"lint\": \"eslint .\",\n    \"serve\": \"firebase serve --only functions\",\n    \"shell\": \"firebase functions:shell\",\n    \"start\": \"npm run shell\",\n    \"local-start\": \"PORT=5000 node src/index.js\",\n    \"deploy\": \"firebase deploy --only functions\",\n    \"logs\": \"firebase functions:log\"\n  },\n```\n\n## Re-Structuring Our Functions Folder\n\nTo keep things organized we're going create a new folder called `functions/src` where most of our code will live.\n\nIn there we'll create our base `functions/src/index.js` which will also reference our other resources.\n\nIn the `functions/index.js` file, we'll modify it from:\n\n```javascript\nconst functions = require('firebase-functions');\n\n// // Create and Deploy Your First Cloud Functions\n// // https://firebase.google.com/docs/functions/write-firebase-functions\n//\n// exports.helloWorld = functions.https.onRequest((request, response) =\u003e {\n//  response.send(\"Hello from Firebase!\");\n// });\n```\n\nand change it to:\n\n```javascript\n// Dependencies\nconst functions = require('firebase-functions');\nconst app = require('./src');\n\n// Export\nexports.app = functions.https.onRequest(app);\n```\n\nNow we can run our server locally on `http://localhost:5000` by running:\n\n```bash\ncd functions;\nyarn run local-start;\n```\n\nWhen we go to `http://localhost:5000` we should see:\n\n```json\n{ \"VERSION\": \"1.0.0\", \"HOST\": \"0.0.0.0\", \"PORT\": \"5000\", \"ENV\": \"development\" }\n```\n\n## Testing Endpoint\n\nTo test one of the new routes, use this curl command in another terminal window:\n\n```bash\ncurl -X POST \\\n  http://localhost:5000/api/posts \\\n  -H 'Accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -H 'cache-control: no-cache' \\\n  -d '{\n\t\"comment\": \"Hello first comment 👋.\"\n}'\n```\n\n## Deployment\n\n**_NOTE_**: You will need to be logged in to `firebase-tools` for this to work, and make sure you are set the correct `project` as well.\n\n**_IMPORTANT_**: Make sure you environment keys / variables are set for production before pushing.\n\n**_NODE_VERSION_**: Make sure you are using node the correct node version (run `nvm use`);\n\n**_LINTING_ERRORS_**: Make sure to fix your linting errors, otherwise it will NOT deploy.\n\n**_DEPLOYMENT_VERSIONING_**: Make sure to increment the deployment version in `functions/src/index.js` to make sure you have an idea if the new code has been deployed.\n\nTo deploy, run:\n\n```bash\n# !!! Make sure you're in the root of the project\n./node_modules/firebase-tools/lib/bin/firebase.js deploy --only functions;\n```\n\nIf successfully deployed, it should be deployed to:\n\n`https://{your-firebase-project}.cloudfunctions.net/app/api`\n\nIf it was successfully deployed, but it's NOT showing, check:\n\n`https://console.firebase.google.com/u/0/project/{your-firebase-project}/functions/logs?severity=DEBUG`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingwithmanny%2Ffirebase-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodingwithmanny%2Ffirebase-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingwithmanny%2Ffirebase-nodejs/lists"}