Skip to content

monirhossain09544/pusher-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-time Notifications Backend with Pusher

Overview

This document provides instructions for setting up a Node.js backend server that integrates with Pusher to send real-time notifications to a Flutter application. The backend is capable of broadcasting messages to any subscribed clients via Pusher Channels.

Getting Started

Prerequisites

  • A Pusher account with an app created on the Pusher Dashboard.
  • Node.js and npm installed on your server.
  • A Flutter app with Pusher client integration.

Installation

  1. Clone or download the backend server code from the repository:

    git clone https://github.com/monirhossain09544/pusher-backend.git
  2. Navigate to the root directory of the backend server code in your terminal.

  3. Run npm install to install all required dependencies.

Configuration

Set up your Pusher instance in the server.js:

const Pusher = require('pusher');

const pusher = new Pusher({
  appId: "YOUR_PUSHER_APP_ID",
  key: "YOUR_PUSHER_APP_KEY",
  secret: "YOUR_PUSHER_APP_SECRET",
  cluster: "YOUR_PUSHER_APP_CLUSTER",
  useTLS: true
});

Usage

Running the Server Start the server by running the following command in your terminal:

node server.js

The server will then listen for incoming HTTP POST requests to trigger notifications.

Triggering Notifications

To send a notification, make a POST request to the /notify endpoint with a JSON payload containing the message. This can be done using Postman or via curl:

curl -X POST -H "Content-Type: application/json" -d "{\"message\":\"Your notification message\"}" http://<YOUR_SERVER_URL>:3000/notify

Be sure to replace <YOUR_SERVER_URL> with the actual URL where your server is hosted.

Flutter App Integration

In your Flutter application, set up subscription to the Pusher channel to listen for messages as shown in the example below:

void initPusher() async {
  await Pusher.init("YOUR_PUSHER_APP_KEY", PusherOptions(cluster: "YOUR_PUSHER_APP_CLUSTER"));
  Pusher.connect();

  Channel channel = await Pusher.subscribe("notification-channel");
  channel.bind("new-notification", (PusherEvent event) {
    // Handle the notification
    print(event.data);
  });
}

Refer to the pusher_websocket_flutter package documentation for detailed integration steps.

Security

When preparing for production, make sure to:

  • Use environment variables to store your sensitive keys and secrets. Implement authentication and authorization mechanisms to protect your
  • endpoints. Use SSL/TLS encryption for securing data in transit.
  • Support For further assistance, refer to the Pusher Channels
    documentation or contact Pusher support.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published