node package manager


Wrap javascript functions according to configurable rules.


This is a utility library used by concurix-monitor. We suggest you check out that library as it will automatically apply this wrapper with logic for integration with the Concurix service.

Javascript wrappers for inserting before and after calls around a function, while preserving as much identity of the wrapped function as possible.

Unlike simple function wrappers, the returned proxy tries to mimic the wrapped function as closely as possible (including properties and name)

To get the most out of this module, you can optionally expose V8's debug as a symbol this module will look for:

node --expose-debug-as=v8debug app.js
var wrap = require("concurix-wrap");
// A silly prime number finder 
function findPrimes(n) {
  var primes = [2], j, isPrime, i = 3
  while (primes.length < n) {
    isPrime = true
    for (= 0; j < primes.length; j++) {
      if (% primes[j] === 0) {
        isPrime = false
    if (isPrime) primes.push(i);
  return primes;
findPrimes = wrap(findPrimes)
  .before(function () {
    console.log("Starting `findPrimes()` at %s", new Date());
  .after(function () {
    console.log("Finished `findPrimes()` at %s", new Date());
var result = findPrimes(100000);
console.log(result[result.length - 1]);
Starting `findPrimes()` at Tue Nov 19 2013 12:25:31 GMT-0800 (PST)
Finished `findPrimes()` at Tue Nov 19 2013 12:25:59 GMT-0800 (PST)


Wrap a function with a proxy that allows you to trigger behavior before or after execution.

Retreive the proxy function that will perform the original task with your added hooks.

Execute fn before the wrapped function begins.

Execute fn after the wrapped function completes. This does not follow asynchronous continuations.

Retreive the original function from the wrapper, unmodified.