Vite+ React
Initial Script
cd frontend
npm i
Run
npm run dev
Node.js Express
Initial Script
cd backend
npm i
Run
npm run dev
- Create Firebase Account and Go to firebase console
- New Web App
- See the Official Docs at https://firebase.google.com/docs/cloud-messaging/js/client

-
Create the Credential file in
frontend/configfromcredential.example.jstocredential.jsand put the config from your firebase console in it. -
Create file
public/firebase-messaging-sw.jsfrompublic/firebase-messaging-sw.example.js -
Create file
.envfrom.env.example(When you import with vite useimport.meta.env.VITE_in create-react-app useprocess.env.REACT_APP_) -
Get the Vapid Key from your public key and keep in .env file

-
On Frontend Focus on Recieve a message
-
Main Logic is on
App.jsxandpublic/firebase-messaging-sw.js -
Firebase Notify is both on Foreground and Backgroud for the foregroud in App.jsx backgroud is in service worker
- In firebase console, go to setting > Service account
and download your service account file

- Save file to backend and named the file
serviceAccount.json - For Document visit https://firebase.google.com/docs/cloud-messaging/send-message
- After Setting Run the program
- Click Register Notify in frontend and wait for token
- Create a post request to
http://localhost:3001/api/testwith JSON style body
{
"token":"notify token from frontend console or toast after",
"message":"Hiiii"
}
can send by postman, apidog or another client
- Watching for the result
The final Result will be like in Foreground

And in background when close the browser

© 2025, Intelligent Automation Engineering Center