Skip to content

Commit

Permalink
Add example using node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
alchemicas committed Mar 30, 2024
1 parent 9b56118 commit 8d10ced
Show file tree
Hide file tree
Showing 8 changed files with 1,093 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
storage.json
35 changes: 35 additions & 0 deletions examples/node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Node.js Example for @aracna/fcm

Please define the following variables inside a .env file.

| Name | Source | Type |
| --------------------------- | ---------------- | ------ |
| VITE_FIREBASE_API_KEY | Firebase Console | string |
| VITE_FIREBASE_APP_ID | Firebase Console | string |
| VITE_FIREBASE_PROJECT_ID | Firebase Console | string |
| VITE_GOOGLE_SERVICE_ACCOUNT | Firebase Console | string |
| VITE_VAPID_KEY | Firebase Console | string |

The `VITE_GOOGLE_SERVICE_ACCOUNT` variable must be base64 encoded.

## Install Dependencies

```
pnpm i
```

## Register & Listen

This command registers a new device to FCM if not already registered, then connects with the client and listens to any incoming messages.

```
pnpm start
```

## Send Test Message

This command will send a test message to the client that is listening when you run `pnpm start`, you should see it appear in its logs once sent.

```
pnpm send-message
```
19 changes: 19 additions & 0 deletions examples/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"send-message": "vite-node src/send-message.ts",
"start": "vite-node src/register-and-listen.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@aracna/core": "^1.1.81",
"@aracna/fcm": "^1.0.22",
"vite": "^5.2.7",
"vite-node": "^1.4.0"
}
}
Loading

0 comments on commit 8d10ced

Please sign in to comment.