DEV Community

Cover image for πŸ”” Notifycli: A Lightweight Go CLI for Firebase Push Notifications
John Afariogun
John Afariogun

Posted on

πŸ”” Notifycli: A Lightweight Go CLI for Firebase Push Notifications

Need to send push notifications to your mobile or web clients β€” from the command line, a backend script, or a CI/CD pipeline β€” without building a full backend server?
Notifycli is a simple, Go-based CLI that does exactly that: use Firebase Cloud Messaging (FCM) credentials + a device token to send push notifications.

In this post, I unpack the code, show installation and usage, and highlight how it's built β€” so you can use or extend it for your own projects.


What is Notifycli?

According to the project README:

  • Notifycli is a β€œGo CLI for sending push notifications to mobile and web devices using Firebase Cloud Messaging.” (GitHub)
  • It supports sending to a single device (via FCM device token), and allows custom data payloads β€” e.g. a title, body, optional URL β€” which your app can use for deep linking or redirection. (GitHub)
  • It uses a clean project structure based on the popular CLI framework Cobra for subcommands and flag parsing. (GitHub)

Because it's a standalone binary (no heavy deps, no web server), it works well for automation: cron jobs, server scripts, deployment hooks, or any backend that just needs to β€œfire-and-forget” an FCM push.


Project Structure & Architecture

Here’s how the repo is structured: (GitHub)

Notifycli/
 β”œβ”€β”€ cmd/
 β”‚    β”œβ”€β”€ root.go         # CLI root command definitions
 β”‚    └── notify.go       # β€œnotify” subcommand: sends a notification
 β”œβ”€β”€ internal/
 β”‚    └── firebase/
 β”‚         └── client.go  # Firebase FCM client wrapper
 β”œβ”€β”€ main.go              # Entry point
 β”œβ”€β”€ go.mod / go.sum      # Module definitions
 β”œβ”€β”€ test/                # (optional) tests
 └── README.md
Enter fullscreen mode Exit fullscreen mode

Highlights:

  • cmd/: Uses Cobra to define commands and flags.
  • internal/firebase/client.go: Encapsulates FCM initialization, authentication using a Firebase service-account JSON key, and the logic to send notifications via FCM REST API. (GitHub)
  • Minimal external dependencies β€” this keeps the binary lightweight and portable.
  • Easy to integrate with scripts, cron jobs, CI/CD pipelines β€” you just call notifcli notify ....

How to Build & Use

1. Clone & Build

git clone https://github.com/johnafariogun/Notifycli.git
cd Notifycli
go build -o notifcli
# optionally:
go install
Enter fullscreen mode Exit fullscreen mode

2. Provide Firebase Credentials

  • Go to your Firebase project β†’ Project Settings β†’ Service Accounts β†’ Generate new private key.
  • Download the serviceAccount.json and place it in your project root (or anywhere you like, but pass its path with --creds). (GitHub)

3. Send a Notification via CLI

notifcli notify \
  --token <DEVICE_FCM_TOKEN> \
  --title "Deployment Successful" \
  --body "Your service is live." \
  --creds /path/to/serviceAccount.json
Enter fullscreen mode Exit fullscreen mode

Optional flag: --url, to include a link in the data payload (useful for app deep links or redirect URLs). (GitHub)

That’s all β€” a simple, one-liner to trigger a push notification from anywhere.


Under the Hood: What’s Going On

  • The CLI parses flags (token, title, body, url, creds) via Cobra in cmd/notify.go. (GitHub)
  • The internal/firebase/client.go module: initializes a Firebase app using the provided service account, constructs the FCM message (with title/body, and optional data payload containing link), and sends the request to FCM via HTTPS. (GitHub)
  • Error handling covers cases like missing credentials, invalid FCM token, or network failures. The CLI prints descriptive error messages. (GitHub)
  • Because it's a native Go binary, it’s cross-platform (Linux, macOS, etc.) and doesn’t require runtime dependencies beyond Go’s standard library + net/http.

Why This Tool Matters

  • Simplicity & Speed: No need to build a full backend just to send notifications.
  • Automation-friendly: Great for deployment scripts, CI/CD, cron jobs, or server-side alerts.
  • Portable: Build once, deploy anywhere.
  • Extensible: You can extend internal/firebase/client.go to support more advanced FCM features β€” e.g. topic messages, batch sends, custom data payloads, image notifications. The architecture is clean and modular. (GitHub)

Wrap-up & Final Thoughts

Notifycli is a great example of how a small, focused tool can do one thing well β€” in this case: send FCM push notifications β€” and integrate easily into scripts, automation, or backend workflows.
Its clean Go + Cobra structure and minimal dependencies make it perfect for developers or DevOps workflows that don’t need a full backend server just for notifications.

If you need a lightweight, scriptable, cross-platform tool for mobile/web push notifications β€” especially useful for deployment alerts, status updates, or automation β€” give Notifycli a try.

Top comments (0)