I'd like to use Vue.js for Frontend and Firebase Functions (Express.js) + Firestore on Backend.
0-step: I created a new project on Google Firebase, I created a new Service Account with Owner's permissions (for use it with Admin SDK later)
1st step: I installed vue-cli v3 and created project:
$ vue create my-project
$ npm run serve //localhost:8080 OK
2nd step:
$npm install firebase firebase-admin firebase-functions --save
Folder structure:
my-project
.firebaserc //created (edited) manually
babel.config.js
firebase.json //created (edited) manually
package.json
dist
node_modules
public
src
assets
components
firebase
functions
index.js //here are my functions
service-accounts
views
firebase.json: (copied from other project and edited manually)
{
"functions:": {
"source": "src/firebase/functions"
},
"hosting": {
"public": "public",
"ignore": [...]
}
}
src/functions/index.js:
import functions from 'firebase-functions';
import admin from 'firebase-admin';
const serviceAccount = require('../service-accounts/owner-key.json');
admin.initializeApp({
credentials: admin.credencial.cert(serviceAccount),
databaseURL: 'my-project.firebaseio.com'
})
const db = admin.firestore();
...
In the package.json file I have added extra scripts:
"deploy": "vue-cli-service build && firebase deploy --only hosting,functions"
but when I run "npm run deploy" command I receive an error:
No npm package found in functions source directory. Please run 'npm init' inside src/firebase/functions
My question is next: why does it need to install firebase functions packages only inside the functions source directory and can I use firebase-functions which I installed in the top-level node_modules folder?