Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

I have installed push.js but it still don't run on node.js backend #292

Open
kuspia opened this issue May 16, 2022 · 3 comments
Open

I have installed push.js but it still don't run on node.js backend #292

kuspia opened this issue May 16, 2022 · 3 comments

Comments

@kuspia
Copy link

kuspia commented May 16, 2022

const express = require('express');
const app = express();
const Push = require('push.js')
app.use(express.json());
app.get('/', (req, res) => {   
res.sendFile(__dirname + '/index.html');
});
app.post('/', async (req, res) => {
var f = 0 ;
// I get values here from the frontend's form and process them and do calculations to update f
if(f>10)
{
Push.create("Hello nice" );
}
else
{
Push.create("POOOOOOOOOOR man try again" );
}
});
app.listen(3000);

I installed push.js as a npm module but I don't understand after my server is started and rendered index.html, I see the following as an error:

image

Please try to understand why I want to do so, in my backend I fetch a value from the frontend's form and then process it and if it is in the range I need to send a push notification somehow to the frontend user which I am failing to do so because of the above error.

I am able to send a notification by making a notify button on the frontend and if the user press it, as I included the .js files in my HTML and things work fine, but I just don't understand what is the use of npm install push.js if a node.js backend is unable to send the notification to frontend when desired.

@thiagolmoraes
Copy link

Same problem!

@matronator
Copy link

matronator commented Apr 23, 2023

The error states: navigator is not defined, which makes sense as navigator is only available in browsers and not in node. I think this library is for browser only. You need to call the Push methods on the frontend.

@xbsheng
Copy link

xbsheng commented Feb 1, 2024

This is the npm library used in front-end web pages and cannot be used in nodejs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants