Server-side events with EventSource.
var http = require'http'eventSource = require'event-source-emitter'httpcreateServervar es = eventSourcereq res keepAlive: truetimes = 0var interval = setIntervalesemit"update" time: Datenowif times++ > 10esendclearIntervalinterval1000listen8765
$ curl -v 127.0.0.1:8765
To connect to the EventSource server, use the browser's EventSource interface.
keepAlive- Boolean, default:
true, send a comment every 15 seconds to guard against timeouts.
onClose- Function, called when the connection is terminated.
Send an event down the event stream.
Close the connection.
Send a message down the event stream. It will be ignored by the receiver.