npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-middleware-bigpipe

v1.0.2

Published

a middleware of express, an implementation of bigpipe

Downloads

10

Readme

#express-middleware-bigpipe

express' bigpipe Middleware.

Build Status

##Start ####Install

npm i express-middleware-bigpipe --save

####Use in express

// express code
var bigpipe = require('express-middleware-bigpipe')

app.use(bigpipe({
    basedir: __dirname + '/public/'
}))

DEMO

##Usage:

本中间件的 namespace 在 res.bigpipe 下, 所有方法都支持链式调用, 输出完成后自动触发res.end()结束请求.

The namespace of this middleware is at res.bigpipe, all methods allow chained call, it will automatically invoke res.end() to end a request when finished pipe.

####write(str);

直接输出, 与res.end类似, 但是不会终止请求

directly pipe a string

####pagelet(file, errHandler);

读取basedir下的file文件, 第二个参数为错误处理回调, 传入参数err

pipe the static file in opts.basedir, errHandler is a callback function to handle errors.

####render(view, renderObj, callback/* optional */);

使用模板引擎读取模板目录下模板, renderObj 为渲染的数据, callback回调采用尾触发, 传入一个参数assign, 在callback中异步获取到数据之后使用assign(obj) 将数据合并入renderObj并渲染输出.

This method use template engine to bigpipe a rendered string.

The callback function have an assign argument which is a function to assign an obj to render asynclly.

该方法可用的重载:

You can also use this method in the following way:

render(view, renderObj);

render(view, callback);

####done(fn);, done(str);

提前结束, 相当于 res.end , 可以传入 String 直接输出, 或者回调函数在 res.end 之前执行.

End the request immediately.

You can also pass a function or string. If it is a func, it will be called before res.end, or if it is a string, it will be passed to res.end(str).

##Quick Demo:

var app = require('express')(),
	bigpipe = require('express-middleware-bigpipe'); // import

//...

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(bigpipe({						 // use bigpipe
	basedir: __dirname + '/public/'     // 设定bigpipe的pagelet路径, set basedir
}));

app.get("/", function(req, res){
	 res.bigpipe.write("<script>alert('this is a test');</script>"); // directly pipe
	 res.bigpipe.pagelet('pagelet.eg.js', function(err){  //  使用 pagelet 读取 basedir 下的文件, 第二个参数为错误处理
         //this is err handle
         console.log('err', err);
     });

	 res.bigpipe.render('pagelet', {
         text: "this is a rendered data"

     }, function(assign) {
         //async coding

         setTimeout(function(){
             assign({
                 anotherData: "3000ms 后输出" // render and pipe after 3000ms
             });
         }, 3000);

     }).render('pagelet', {
         text: "123321",
         others: "balabala"
     });

});

##Test

npm test

Use mocha and supertest

By Ling created @ 2015-04-29 21:10:36 www.zeroling.com

Follow me at https://github.com/wssgcg1213

Report issue at https://github.com/wssgcg1213/express-middleware-bigpipe/issues