简体   繁体   English

使用AngularJS处理Node.js流

[英]Handling Nodejs streams with AngularJS

I am using nodejs streams to fetch data from my level database (using leveldb). 我正在使用nodejs流从我的关卡数据库中获取数据(使用leveldb)。 Here is a snippet of the code I use: 这是我使用的代码片段:

  app.get('/my/route', function (req, res, next) {

    leveldb.createValueStream(options)
    .pipe(map.obj(function (hash) {
        level.get(somekeys, function (err, item) {

          return item
        })
      }))
    .pipe(res)
  })

So far, I have been using the list-stream module to get the data on the client side. 到目前为止,我一直在使用list-stream模块在客户端获取数据。

Now I'd like to retrieve the information on the client side as a stream. 现在,我想以流的形式检索客户端上的信息。 I've read this post ( http://www.kdelemme.com/2014/04/24/use-socket-io-to-stream-tweets-between-nodejs-and-angularjs/ ) on how to do it using socket.io but I don't want to use socket.io 我已经阅读了有关如何使用它的文章( http://www.kdelemme.com/2014/04/24/use-socket-io-to-stream-tweets-between-nodejs-and-angularjs/ ) socket.io,但我不想使用socket.io

Is there any simple way to do it? 有什么简单的方法吗?

This can be done with Shoe . 这可以通过Shoe来完成。 You have to compile the client code with browserify and you can have a stream in the browser that receives the data from the server. 您必须使用browserify编译客户端代码,并且浏览器中可以具有从服务器接收数据的流。

The createValueStream basically is a read stream, then you can listen to the event eg., data , end : https://github.com/substack/node-levelup#createValueStream createValueStream基本上是一个读取流,然后您可以侦听事件,例如dataendhttps : //github.com/substack/node-levelup#createValueStream

Just need to listen to end event to finish the stream. 只需要听end事件来完成流。

  app.get('/my/route', function (req, res, next) {

    leveldb.createValueStream(options)
    .pipe(map.obj(function (hash) {
        level.get(somekeys, function (err, item) {
          return item
        })
      }))
    .pipe(res)
    .on('end', res.end)
  })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM