Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Admin Nodejs cannot find module service_account.json

I start my node with "node firebasedb.js". My firebasedb.js contains this code:

var admin = require("firebase-admin");

var serviceAccount = require("service_account.json");

// Initialize Firebase
var config = {
    credential: admin.credential.cert(serviceAccount),
    apiKey: "<api key>",
    authDomain: "<auth domain>",
    databaseURL: "<database url>",
    storageBucket: "<storage bucket>",
};

admin.initializeApp(config);

When I run node, I am in the directory where the .json file exists. But it says

Error: Cannot find module 'service_account.json'
like image 327
Zik Avatar asked Apr 02 '17 08:04

Zik


Video Answer


1 Answers

You are missing the relative portion of the required path. That is, you should doing something like this:

var serviceAccount = require("./service_account.json");

If it's not a relative path, require will be looking in node_modules for a module named service_account.json.

like image 112
cartant Avatar answered Sep 22 '22 18:09

cartant