Handling Nodejs streams with AngularJS
Asked Answered
C

2

0

I am using nodejs streams to fetch data from my level database (using 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.

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

Is there any simple way to do it?

Chromatism answered 10/10, 2014 at 13:15 Comment(1)
I'd throw the stream directly to the response from the server, not passing it over angularjsHonna
N
0

This can be done with 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.

Nazi answered 4/12, 2014 at 21:55 Comment(0)
U
0

The createValueStream basically is a read stream, then you can listen to the event eg., data, end: https://github.com/substack/node-levelup#createValueStream

Just need to listen to end event to finish the stream.

  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)
  })
Urn answered 5/4, 2018 at 4:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.