Node.js 使用AngularJS处理Nodejs流
我使用nodejs流从我的级别数据库(使用leveldb)获取数据。以下是我使用的代码片段:Node.js 使用AngularJS处理Nodejs流,node.js,angularjs,sockets,stream,Node.js,Angularjs,Sockets,Stream,我使用nodejs流从我的级别数据库(使用leveldb)获取数据。以下是我使用的代码片段: app.get('/my/route', function (req, res, next) { leveldb.createValueStream(options) .pipe(map.obj(function (hash) { level.get(somekeys, function (err, item) { return item
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)
})
到目前为止,我一直在使用列表流
模块在客户端获取数据
现在我想在客户端以流的形式检索信息。我已经阅读了这篇关于如何使用socket.io的文章(),但我不想使用socket.io
有什么简单的方法吗?这可以用。您必须使用browserify编译客户端代码,并且您可以在浏览器中拥有一个从服务器接收数据的流。基本上,
createValueStream
是一个读取流,然后您可以收听事件,例如,数据
,结束
:
只需收听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)
})
我会将流直接从服务器抛出到响应,而不是通过angularjs传递