nodejs/express - stream stdout instantly to the client

前端 未结 3 477
难免孤独
难免孤独 2020-12-24 02:39

I spawned the following child: var spw = spawn(\'ping\', [\'-n\',\'10\', \'127.0.0.1\']) and I would like to receive the ping results on the client side (

3条回答
  •  自闭症患者
    2020-12-24 03:26

    If you are using Google Chrome, changing the content-type to "text/event-stream" does what your looking for.

    res.writeHead(200, { "Content-Type": "text/event-stream" });
    

    See my gist for complete example: https://gist.github.com/sfarthin/9139500

提交回复
热议问题