{
    "componentChunkName": "component---src-templates-blog-post-js",
    "path": "/how-to-create-firebase-function/",
    "result": {"data":{"site":{"siteMetadata":{"title":"CrewCode Solutions"}},"markdownRemark":{"id":"b4fc562c-2e59-5977-afbb-8112e8ed3064","excerpt":"In this article iam gonna explain you how you can create firebase function, deploy and work with firebase function Step 1: Create a Firebase Project or you can…","html":"<p>In this article iam gonna explain you how you can create firebase function, deploy and work with firebase function</p>\n<h4>Step 1: Create a Firebase Project or you can skip this step of you have already created your firebase project</h4>\n<ul>\n<li>\n<p>Go to <a href=\"https://firebase.google.com\">https://firebase.google.com</a> and click on Get Started</p>\n</li>\n<li>\n<p>Proceed to click on Create a project.</p>\n</li>\n<li>\n<p>Enter a project name and check yes if you wish to add analytics to your project.</p>\n</li>\n<li>\n<p>Wait for the project to be created.</p>\n</li>\n</ul>\n<h4>Step 2 Install firebase tools and initialize firebase function</h4>\n<ul>\n<li><strong><em>Run below command to install firebase tools globally</em></strong></li>\n</ul>\n<pre><code class=\"language-js\">npm install -g firebase-tools\n</code></pre>\n<ul>\n<li><strong><em>Initialize firebase function</em></strong></li>\n</ul>\n<pre><code class=\"language-js\">firebase login\n</code></pre>\n<pre><code class=\"language-js\">firebase init\n</code></pre>\n<ul>\n<li><strong><em>Select Functions option in below step</em></strong></li>\n</ul>\n<pre><code class=\"language-js\">$ firebase init\n> ? Which Firebase features do you want to set up for this directory? Press Space to select features, then Enter to confirm your choices\n. (Press &#x3C;space> to select, &#x3C;a> to toggle all, &#x3C;i> to invert selection, and &#x3C;enter> to proceed)\n❯◯ Realtime Database: Configure a security rules file for Realtime Database and (optionally) provision default instance\n ◯ Firestore: Configure security rules and indexes files for Firestore\n ◯ Functions: Configure a Cloud Functions directory and its files\n ◯ Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys\n ◯ Hosting: Set up GitHub Action deploys\n ◯ Storage: Configure a security rules file for Cloud Storage\n ◯ Emulators: Set up local emulators for Firebase products\n(Move up and down to reveal more choices)\n</code></pre>\n<ul>\n<li><strong><em>Select Language</em></strong></li>\n</ul>\n<pre><code class=\"language-js\">? What language would you like to use to write Cloud Functions? (Use arrow keys)\n❯ JavaScript\n  TypeScript\n</code></pre>\n<ul>\n<li><strong><em>Install packages</em></strong></li>\n</ul>\n<pre><code class=\"language-js\">? What language would you like to use to write Cloud Functions? JavaScript\n? Do you want to use ESLint to catch probable bugs and enforce style? No\n✔ Wrote functions/package.json\n✔ Wrote functions/index.js\n✔ Wrote functions/.gitignore\n? Do you want to install dependencies with npm now? (Y/n) Yes\n</code></pre>\n<h4>Step 3 Write your function inside functions/index.js file and deploy</h4>\n<p>Once function initialized and created you will see a folder functions and inside that folder you will have a main file named as index.js where you can define your function</p>\n<p>A example function has already been created for you just un comment that</p>\n<pre><code class=\"language-js\">const functions = require(\"firebase-functions\");\n\n// // Create and Deploy Your First Cloud Functions\n// // https://firebase.google.com/docs/functions/write-firebase-functions\n//\nexports.helloWorld = functions.https.onRequest((request, response) => {\n  functions.logger.info(\"Hello logs!\", { structuredData: true });\n  response.send(\"Hello from Firebase!\");\n});\n</code></pre>\n<ul>\n<li><strong><em>Deploy your function using below command</em></strong></li>\n</ul>\n<pre><code class=\"language-js\">firebase deploy --only functions\n</code></pre>\n<ul>\n<li><strong><em>Once deployed you can access the function just replace the project id with your firebase project id</em></strong></li>\n</ul>\n<pre><code class=\"language-js\">https://us-central1-&#x3C;project-id>.cloudfunctions.net/helloWorld\n</code></pre>","fields":{"slug":"/how-to-create-firebase-function/"},"frontmatter":{"title":"How to create, deploy and work with firebase function","date":"September 30, 2022","description":"In this article i will explain you step by step how you can create firebase function, deploy and create firebase function","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/firebase-node.jpeg"}},"previous":{"fields":{"slug":"/graphql-apollo-node-mongodb-restapi/"},"frontmatter":{"title":"Create GraphQl API with Apollo Server, Node and MongoDb","date":"September 22, 2022","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/GraphQL.jpg"}},"next":{"fields":{"slug":"/how-to-work-with-angular-universal/"},"frontmatter":{"title":"How to add angular universal for server side rendering in your angular application","date":"October 01, 2022","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/angular-universal.jpeg"}}},"pageContext":{"id":"b4fc562c-2e59-5977-afbb-8112e8ed3064","previousPostId":"4dc7e8b2-b7fd-5770-a45d-a4cc712e79c2","nextPostId":"735286e7-b398-58cf-a138-0a8404d5ee5e"}},
    "staticQueryHashes": ["3860684146"]}