Nuxt Setup Firebase Functions and Test With Emulator

Nuxt.js Setup

Setup Firebase for Nuxt.js.

Edit nuxt.config.js to allow functions to access emulator.

export default {  modules: [    '@nuxtjs/firebase',  ],  firebase: {    config: { ... },    services: {      functions: {        location: 'us-central1',        emulatorHost: 'http://localhost',        emulatorPort: 5001,      }    }  }}

Call the firebase cloud function.

<script>export default {  methods: {    async callHello() {      const hello = this.$fire.functions.httpsCallable('hello');      const result = await hello({name: 'Desmond'})      console.log(result.data)    }  },  mounted() {    callHello()  }}</script>

Firebase Cloud Functions

Setup Firebase Project with Functions.

Edit functions/index.js

const functions = require('firebase-functions');exports.hello = functions.https.onRequest(async (request, response) => {  const name = request.query.name;  response.send(`Hello ${name}`)})

Test

In firebase project, start emulator.

firebase emulator:start

In nuxt project, start dev.

npm run dev

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.