How to send a message to node.js server? - node.js

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.

Related

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

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.

Database changes notifications (Angular4 client, NodeJS server)

I'm developing an Angular 4 app that connects to a REST API developed in NodeJS/Express/MySQL. I'm looking for a way to notify any connected clients when there is a change in the database, so they reload their datasets. I've done some searches on Google but I don't know the technical term of what I'm looking for, so I didn't find anything useful.
Can someone point me some resource on this subject? Thanks!
You have two options avaliable
1)HTML5 serversent events
A server-sent event is when a web page automatically gets updates from
a server.
https://www.w3schools.com/html/html5_serversentevents.asp
2)Socket.io
https://socket.io/
Based on my experience for simple realtime updates HTML5 server sent is enough
If you want to visualize changes "live", you should try websockets.
With websockets you could notify any client about any upcoming changes in data, think of it as some kind of chat between server and clients.
There's socket.io for Node.js developers and plenty of tutorials about how to set it up and get it running.
Thanks!
Time to learn some new things... I think I'll start with HTML5 Server Send Events, I think it'll be more than enough for what I need.
Cheers,

Is socket.io implementation possible inside REST framework?

I am building an app in which I provide functionality X, Y and chat.
Lets say that X and Y are non-interactive eg. reading articles - which will work fine with REST (on a node.js server) while chat is obviously interactive so it will work best with socket.io!
Questions: 1. Is it possible for me to 'switch on' a socket between the server and the user when the user navigates to the chat part of the application? 2. Can I open up a socket inside a GET request for the url: example.com/chats/usr_id on the node.js server?
3. How can this be accomplished inside a Backbone routing framework?
Yes. Just initialize the connection when the view is rendered (via a controller or script). See socket.io client documentation. You can just connect when the view is rendered and disconnect when the view is terminated. http://socket.io/docs/client-api/
You cannot open sockets with a GET request. Socket.io has it's own build in mechanisms for connecting to a socket server. It will start with Web Socket protocol and fall back to Long Polling. You can however use custom url's for unique things. One again, consult the socket.io documentation: http://socket.io/docs/client-api/
http://www.sitepoint.com/chat-application-using-socket-io/
p.s. I'd suggest reading up on how Web Sockets work, as you don't seem to have a very strong understanding.

Realtime application - alternative for socket.io (node.js)

I use node.js.
I am looking for an alternative for socket.io.
I need to send a private message to the user.
What is the alternative for the SOCKET.IO?
You haven't really explained why you're looking for Socket.IO. If you provide more details into why Socket.IO isn't working for you then you can get a better answer. Otherwise I'll just point you to a duplicate of this question.
Node.JS Looking for an alternative to socket.IO

Passing streaming of Http response to a web page using node.js

Following up on this question I was wondering is there is a way, without using socket.io, to avoid the buffering of the response that happens on most navigators. So for instance if the node server emit every 5 secondes : 'hello world' i can directly print them on a webpage as soon as the data is available.
Is there a way to do so ?
Unfortunately, this is not how web browsers work. If you want this type of functionality without using WebSockets (or a socket.io fallback) you could try with Server-Sent Events. See this gist for an example (in coffeescript). Also, here is a polyfill for older browsers.
Yes, this is doable. This is how comet streaming servers work.
See http://faye.jcoglan.com/ for an example for Node.js.

Resources