Skip to content

stackhero-io/mercureHubGettingStarted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

93a4c03 Â· Mar 27, 2023

History

9 Commits
Mar 27, 2023
Feb 11, 2020
Dec 17, 2018
Sep 15, 2022
Dec 17, 2018

Repository files navigation

Mercure-Hub: getting started

How to send data from Node.js to Mercure-Hub and receive them in the browser

You can find here some examples of Node.js code to send data to a Mercure-Hub server.

These examples are designed to run with a Stackhero Mercure-Hub service. You'll more informations about Stackhero here:

How to use

Screenshot

First you have to create a Mercure Hub service on Stackhero.

In Stackhero's configuration, allow "anonymous subscribers" to let the client connect to topics without authentication.

Front end

In frontend/susbcriber.html, fill the endpoint (domain name of Stackhero's service).

Then open the file susbcriber.html in your browser.

Back end

Fill the configuration informations in backend/.env-example and rename the file to .env. Then start the server with npm run start.

The back end code will send datas every seconds to the Mercure Hub, on a the topic /books/1. The frond end will listen datas from the topic /books/1 and display them.

Congratulations, you have a Mercure Hub up and running! 🎉