How could i send notfication app to web in node js i am new to nodejs please if you can - node.js

i have to send a notification on web when a event occurs on app

Assuming you are using ReactJS, you need to use WebSockets. Check this tutorial on how to achieve that.

If the event dispatches from server, you can use Socket.IO, but if there is no hurry in getting notifications you can request in AJAX form every (for example) 5 minutes from client side code, to check if there are any notifs or not.

Related

How to use traccar api to get realtime location automatically without setinterval or socket

I'm using node.js and express, while getting the live location using WebSocket, sometimes getting the error or disconnecting the service. I tried to use the setInterval function but the server is calling each 5 seconds is not good. I want real-time data and without a request from the client-side. How?
You need a server push solution e.g. websocket, SSE, etc. It does not need to send real data, just the notification that the client should refresh, because there is new data for it or maybe a hyperlink to follow. After the client gets the notification, it can do HTTP requests.

Send Notification to dashbord app When New order is created in Database using Nodejs

Commerce web app. i want to send notification to be showed in dashboard when new order is created.how can i achieve this using MEAN stack (mongodb express angular and node). can i do this using socket.io. what is procedure to be followed.
You are correct in looking towards socket.io. Socket.io will allow you to do this very easily.
Frankly, you should be able to read the tutorial linked below and know what you need to do, as notifications are probably the easiest thing you could do with socket.io.
http://socket.io/get-started/chat/
Basically what you'd want to do is have your clients listen for an event from socket. You'll emit the event from socket when a new order is created.

server send push notification to client browser without using polling

I am developing a web app in which I want that when some changes in database occurs, server sends response to particular client(like push notification). And I want this notification to be sent client's browser. I don't want to use polling.
What can I do?
I think it's possible using SSE, but I am not clear.
I want to know
Is it possible to send response to particular client without client's request(without polling).
How server will detect that particular client?
please help me.
There is Web Notification. And there you can see the browsers that support it.

How to send a message to node.js server?

How would I send a command to Node.js
I have a jquery / javascript page which detects on keypress W,A,S Or D and then triggers an event to change the canvas.
The next step in this is to then trigger a event on a Node.js server using (I think) Websockets.
Most tutorials I have found are the other way around with sending data to the client.
Does anyone have places with tutorials on how I would do this?
Thanks - Ryan
Use web sockets, tutorial is here http://socket.io/
You can do this with normal ajax calls to Node.js. If you want something more fancy checkout socket.io.

Using node.js and socket.io with PHP application

I have working PHP application. It allows user create private projects and invite others in it. Now, using node.js and socket.io, I want to make real-time comments, posts etc.
What is the best architecture?
I see two solutions now.
The first is:
User sends AJAX query to PHP backend:
http://example.com/comment_add.php?text=...
comment_add.php adds
comment to database and via AMPQ (or something better?) notifies
node.js server which broadcasts comment to channel's subscribers.
The second is:
User sends AJAX query to node.js server: http://example.com:3000/comment_add
Node.js sends request to PHP backend (But how? And what about authorization?), receives response, and then broadcasts to channel's subscribers.
What is the best way? Is there another methods? How to implement this properly?
When you decided to use node.js + socket.io to make a real-time web-app, you don't need to think about PHP anymore and forget Ajax also... Socket.io will be the communication between client and server.
But yes, you can use Ajax and PHP for building websites fast, and some other functions that don't need real-time
The second way is the best method. You can use http to communicate with PHP from node.js. Authorization can be done in node.js but passing auth credentials everytime to PHP
Finally my working solution is #1.
When user establishing connection to node.js/socket.io he just send 'subscribe' message to node.js with his PHP session id. Node.js checks authorization using POST request to PHP backend and if all is OK allows user to establish connection.
Frontend sends all requests to PHP as it was before node.js.
PHP modifies some object, checks who can access modified object and sends message (via AMQP or redis pub/sub etc.) to node.js:
{
id_object: 125342,
users: [5, 23, 9882]
}
node.js then check who from listed users have active sockets and for each user sends GET request to PHP:
{
userId: 5,
id_object: 125342
}
Special PHP controller receiving this request runs query to get object with rights of given user id and then sends message to node.js with resulting answer. Node.js then via socket sends answer to user's frontend.
I faced this same question a year ago when starting my final year project at University. I realized that my project was much better suited to using Node as a standalone. Node is very good at dealing with I/O, this can be anything from a HTTP requests to a database query. Adding in a PHP based Web Server behind Node is going to add un-needed complexity. If your application needs to perform CPU intensive tasks you can quite easilly spawn 'child' node processed which perform the needed operation, and return the result to your parent node.
However out of the two you methods you have mentioned I would choose #2. Node.js can communicate with your PHP server in a number of ways, you could look at creating a unix socket connection between your PHP server and Node. If that is unavailable you could simply communicate between Node and your PHP back end using HTTP. :)
Take a look here, here is a solution to a question very similar to your own:
http://forum.kohanaframework.org/discussion/comment/57607

Resources