ac360
ac360

Reputation: 7835

Zip Files & Folders With No Base Directory

AWS Lambda requires a zip file that produces a file when it's unzipped.

However, every node.js zip library produces a zip file that contains a base folder, containing the files Lambda needs, which breaks Lambda, resulting in a 'Cannot find module' error.

For example, if I have a index.js file and a node_modules directory in the dist folder, when I use gulp-zip, I get an added root folder when the zip file is unzipped...

gulp.src(['./dist/**/*'])
        .pipe(zip('dist.zip'))
        .pipe(gulp.dest('./'))

// When unzipped, this results in a "dist" folder containing index.js and node_modules

I've tried 6 node zip libraries and none have a simple way of excluding the base directory.

Any thoughts?

Upvotes: 1

Views: 1296

Answers (1)

user1504877
user1504877

Reputation: 310

I've used 'node-archiver', which can zip a directory to a destination directory (which I just set as an empty string).

https://github.com/archiverjs/node-archiver#directorydirpath-destpath-data

var archiver = require('archiver');
archive = archive.directory('./directoryToZip/', '' ); //option 2 is the dest
archive.pipe(  outZip);
archive.finalize();

Upvotes: 1

Related Questions