Passing streaming of Http response to a web page using node.js - 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.

Related

WebRTC: Transmit message from Node to Browser

I'd like to know how could I use webRTC to send a message from Node.JS to my Browser without having to install any third-party lib on the Browser end.
I've researched a few options but they all were outdated or over complicated. I just need to print something on the console, no UI, no nothing.
Maybe someone could help me out with a snippet or example?
Thank you
the easiest way is to use socket.io to send node server to browsers without having to install any plugin or lib on browser side(you need to add socket.io.js to your code). onces you setup socket.io you can basicly send data from node server to browser by
client.emit("message",message);
and you can get this from client side like
socket.on("message",function(message){
//do something with message
}};
you can find more information from https://socket.io/docs/ about socket.io
if you would like to send data from browser to browser you need to set up a signaling server to connect the peers. from https://github.com/webrtc/samples link you can find lots of examples for WebRTC implementations for different scen

Connect chrome extension to an application

I want to send a message from chrome extension to a windows application. first i decided to use socket but i realized that we can use socket just in chrome app . is there any way to send this message to achieve my goal ?
The are 2 principal ways to do it.
You could expose a web server instead of raw sockets, something like a REST API. This is available to extensions.
Even better, you could use the WebSocket technology to approximate raw sockets - but you'll need to do all the handshaking first.
There's a specific API for what you're trying to do, called Native Messaging. It's somewhat rigid in what it can do (it cannot connect to an existing process, for instance), but it's worth a look.

how to log OUTGOING https requests from node within webstorm

I'm hacking together some node.js code that calls an external webservice and I'm getting bad results. I'd like to log the raw request and response so that I can inspect it.
Here's the thing: I'm not consuming the http library directly, I'm consuming it through an OAuth library.
I'm already adding debug statements in the oauth library code and I don't like it. Now it looks like I'm going to have to go into http library and start messing with that? This can't be correct.
If I was on windows, I'd fire up fiddler. A friend mentioned wireshark but wireshark tells me I have to install X11. Really? I'm not going down that rabbit hole.
Then I tried node-inspector, but I think that is for server code not client code. It says your suppose to start your node process before attaching. Well my node process is a test case (vows) that ends shortly after is starts... so no luck there.
I guess this would difficult with any stack but jeez, it makes me miss .net!
So, how can I inspect what's going over the wire when using node.js as client to external webservice on mountain lion?
thanks!
Dan
Managed to install a hook on http/https request for the same reason.
function requestLogger(httpModule){
var original = httpModule.request
httpModule.request = function(options, callback){
console.log(options.href||options.proto+"://"+options.host+options.path, options.method)
return original(options, callback)
}
}
requestLogger(require('http'))
requestLogger(require('https'))
You can check out the global-request-logger module, which uses the same technique that #uiron mentioned, but with more details.

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.

Node.js: Receive events from browser

How do I receive events from the browser in my node.js code? (e.g: I imagine Mixpanel, kissmetrics, etc do something like this?
thanks
The same way any other web server receives events from the browser: the browser makes an HTTP request to the URL of your server and the server receives that request. Listening for HTTP requests is the "Hello World" example for node.js.
What you're looking for is http://hummingbirdstats.com/ realtime stats 20 times a second.
You should also checkout socket.io if you haven't. Websockets events are faster than HTTP requests.
You have to send them to your server, via AJAX or some similar method.
Remember, node code runs on the server; the browser runs on the client. The way to get information back and forth from a server to a client running a web browser is an HTTP request.
I recommend dnode. Search for dnode on the browser in the README. It's a quick and complete example of making a RPC. In this case the remote function would be an event handler.
It uses socket.io, which supports websockets, flash sockets, and xhr.

Resources