1.3.0 • Published 10 years ago

node-cover v1.3.0

Weekly downloads
53
License
-
Repository
-
Last release
10 years ago

Cover

简介...

Basic Usage

var cover = require( 'node-cover' );

var app   = cover();

var fs    = require( 'fs' );

var thunkify = require( 'thunkify' );

var readFile = thunkify( fs.readFile );

// connect 中间件
app.use( function( req, res, next ){

  console.log( req.url );

  next();

} );

// koa 中间件
app.use( function *( req, res, next ){
  
  yield next;

} );

app.use( function *( req, res, next ){

  var fileContent = yield readFile( './test.txt', 'utf-8' );

  res.end( fileContent );

} );

app.listen( 8000 );

全局的错误事件

var cover = require( 'node-cover' );

var app   = require( 'app' );


// normal function

app.use( function( req, res, next ) {
  
  throw new Error( 'this is an error' );

} );

// or generator

app.use( function *( req, res, bext ){
  
  throw new Error( 'this is an error' );

} )

app.on( 'error', function( error ){
  console.log( error.message, error.stack );
) };

app.listen( 8000 );

在中间件中捕获错误

connect式的中间件

app.use( function *( req, res, next ){
  try {
    yield next
  } catch ( e ) {
    console.log( e )
  }
} );

app.use( function( req, res, next ){
  throw new Error( 'this is an error' );
} );

koa式的中间件

app.use( function *( req, res, next ){
  try {
    yield next;
  } catch( e ) {
    console.log( e );
  }
  
} );

app.use( function *( req, res, next ){
  throw new Error( 'this is an error' );
} )
1.3.0

10 years ago

1.2.0

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago