title: Firebase messaging, Failed to determine project ID for Messaging
body: <p>How can I initialise my app for messaging? I keep getting the error </p>
  
  <p><strong>"Error: Failed to determine project ID for Messaging. Initialize the SDK with service account credentials or set project ID as an app option. Alternatively set the GOOGLE_CLOUD_PROJECT environment variable."</strong></p>
  
  <p>when I try and invoke <code>messaging</code></p>
  
  <pre><code>const functions = require("firebase-functions");
  const admin = require("firebase-admin");
  
  const config = {
      type: "service_account",
      project_id: "xxx",
      private_key_id: "xxx",
      private_key:
          "-----BEGIN PRIVATE KEY-----xxx-----END PRIVATE KEY-----\n",
      client_email:
          "firebase-adminsdk-8dd2o@pushmessage-bd1eb.iam.gserviceaccount.com",
      client_id: "107357357611247077666",
      auth_uri: "https://accounts.google.com/o/oauth2/auth",
      token_uri: "https://oauth2.googleapis.com/token",
      auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
      client_x509_cert_url:
          "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-8dd2o%40pushmessage-bd1eb.iam.gserviceaccount.com"
  };
  
  admin.initializeApp({
      config
  });
  
  const db = admin.firestore();
  const messaging = admin.messaging();
  
  const message = {
      data: { title: "Testing", body: "Test" },
      tokens: registrationTokens
  };
  
  messaging.sendMulticast(message).then(response =&gt; {
      console.log(response.successCount + " messages were sent successfully");
  });
  </code></pre>