Install firebase-admin, which is for server-side.
npm install firebase-admin
Generate private key
for the project.
- Navigate to https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk
- Select the project
- Go to
Service accounts
tab - Click
Generate new private key
to generate private key - Download and store the json file
Create an index.js
in your project, and paste the following code into it.
import * as admin from 'firebase-admin';
const certificate = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(certificate)
});
Install the required products
or libraries
.
- Navigate to https://firebase.google.com/docs/web/setup
- Select
With npm
tab if you are using npm or yarn, else selectFrom the CDN
tab - Import the core SDK. Eg:
<script src="https://www.gstatic.com/firebasejs/8.7.1/firebase-app.js"></script>
- Go to https://firebase.google.com/docs/web/setup#libraries-cdn, expand
using bundler with modules
if your are using npm else expandfrom the CDN
. - Look for
Cloud Messaging
and import it.
Generate public key
- Navigate to https://console.firebase.google.com/u/0/project/_/settings/cloudmessaging
- Select your project
- Go to
Cloud Messaging
tab - Click
Generate key pair
- Copy the generated
key pair
for later use
** Note **
You must create firebase-messaging-sw.js
to make this work