title: How to automatically zip files with Node.js and npm
body: <p>Is there a way to automatically zip certain files at the build time with Node.js and npm?</p>
  
  <p>For example, I have a project, that file structure looks like this:</p>
  
  <pre><code>Project/
  --lib/
  --node_modules/
  --test/
  --index.js
  --package.json
  </code></pre>
  
  <p>I want to be able to zip lib folder, certain modules from node_modules and index.js into some zip archive to upload it on the AWS Lambda, for example. I do not need test folder or test Node.js modules (mocha and chai) to be zipped. I have even created a bash script for generating zip file, but is there a way to automatically execute this script, when 'npm install' is called?</p>
  
  <p>This should be a standard problem and it should have a standard solution, but I was unable to discover such. </p>
  
  <h3>UPDATE</h3>
  
  <p>thanks to michael, decided to use gulp. This is my script, in case some one else will need it for AWS Lambda:</p>
  
  <pre><code>var gulp = require('gulp');
  var clean = require('gulp-clean');
  var zip = require('gulp-zip');
  var merge = require('merge-stream');
  
  gulp.task('clean', function () {
      var build = gulp.src('build', {read: false})
          .pipe(clean());
      var dist = gulp.src('dist', {read: false})
          .pipe(clean());
  
      return merge(build, dist);
  });
  
  gulp.task('build', function() {
      var index = gulp.src('index.js')
          .pipe(gulp.dest('build'));
      var lib = gulp.src('lib/**')
          .pipe(gulp.dest('build/lib'));
      var async = gulp.src('node_modules/async/**')
          .pipe(gulp.dest('build/node_modules/async'));
      var collections = gulp.src('node_modules/collections/**')
          .pipe(gulp.dest('build/node_modules/collections'));
      var underscore = gulp.src('node_modules/underscore/**')
          .pipe(gulp.dest('build/node_modules/underscore'));
      var util = gulp.src('node_modules/util/**')
          .pipe(gulp.dest('build/node_modules/util'));
      var xml2js = gulp.src('node_modules/xml2js/**')
          .pipe(gulp.dest('build/node_modules/xml2js'));
  
      return merge(index, lib, async, collections, underscore, util, xml2js);
  });
  
  gulp.task('zip', ['build'], function() {
      return gulp.src('build/*')
          .pipe(zip('archive.zip'))
          .pipe(gulp.dest('dist'));
  });
  
  gulp.task('default', ['zip']);
  </code></pre>