browserify api use to file without gulp to trigger callback on success

Does anyone know of a way of triggering a callback once browserify has written the output to disk?



var fs = require('fs');
var browserify = require('browserify');
var b = browserify({standalone: 'MyAppModules'});
b.add('./browserifyMain.js');
b.bundle().pipe(fs.createWriteStream(__dirname + '/public/js/bundle2.js'));


This works, but i need to run an rsync only when the bundle is built.



I tried adding an 'on' event listener based on this post: How to use the new Browserify API?



var fs = require('fs');
var browserify = require('browserify');
var b = browserify({standalone: 'MyAppModules'});
b.add('./browserifyMain.js');
b.bundle().pipe(fs.createWriteStream(__dirname + '/public/js/bundle.js')).on('end', function(){
console.log( 'finished writing the browserify file' );
});


But the log is never returned so i am assuming this doesn't work either :/



Also, tried, but did not work either:



var fs = require('fs');
var bundleFs = fs.createWriteStream(__dirname + '/public/js/bundle.js');
var browserify = require('browserify');
var b = browserify({standalone: 'MyAppModules'});
b.add('./browserifyMain.js');
b.bundle().pipe( bundleFs )
bundleFs.on('end', function(){
console.log( 'finished writing the browserify file' );
});
return;


(all of the above do write the file correctly though)