{"id":11464,"library":"node-zip","title":"node-zip: Legacy Zip/Unzip Utility","description":"node-zip is a Node.js library for zipping and unzipping files, originally ported from an older version of JSZip. The current and only stable version is 1.1.1, which was last published over a decade ago in May 2015. This package is explicitly identified as a legacy and unmaintained project by the wider Node.js community, with strong recommendations against its use in new development due to potential security vulnerabilities, lack of modern features, and inherent performance limitations for large files. Modern alternatives like `jszip`, `adm-zip`, or `zip-stream` are recommended for active projects, offering better maintenance, asynchronous APIs, and streaming capabilities.","status":"abandoned","version":"1.1.1","language":"javascript","source_language":"en","source_url":"git://github.com/daraosn/node-zip","tags":["javascript","zip","unzip","jszip","node-zip","compression"],"install":[{"cmd":"npm install node-zip","lang":"bash","label":"npm"},{"cmd":"yarn add node-zip","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-zip","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and the primary export is a constructor function. It does not support ES Modules (`import`).","wrong":"import Zip from 'node-zip'; // ESM is not supported\nimport { Zip } from 'node-zip'; // Not a named export\nconst zipInstance = require('node-zip'); // 'new' keyword is required","symbol":"Zip","correct":"const Zip = require('node-zip');\nconst zipInstance = new Zip();"}],"quickstart":{"code":"const fs = require('fs');\nconst Zip = require('node-zip');\n\n// --- Zipping a file ---\nconst zip = new Zip();\nzip.file('my_test.txt', 'Hello, this is a test file content.');\nzip.file('another_folder/image.jpg', 'fake image data here, imagine a buffer'); // Can add binary data\n\nconst zippedData = zip.generate({ base64: false, compression: 'DEFLATE' });\n\n// IMPORTANT: When writing to a file, use 'binary' encoding.\nfs.writeFileSync('output.zip', zippedData, 'binary');\nconsole.log('Successfully created output.zip');\n\n// --- Unzipping a file ---\n// For demonstration, we'll read the file we just created\nconst zipBuffer = fs.readFileSync('output.zip', 'binary');\n\nconst unzip = new Zip(zipBuffer, { base64: false, checkCRC32: true });\n\nconsole.log('\\n--- Unzipped Content ---');\nconsole.log('Content of my_test.txt:', unzip.files['my_test.txt'].asText());\n// For binary files, you'd access .asBinary() or .asNodeBuffer()\nconsole.log('File metadata for another_folder/image.jpg:', unzip.files['another_folder/image.jpg']);","lang":"javascript","description":"This quickstart demonstrates how to create a ZIP archive with text and binary content, save it to disk, and then read/extract files from the created ZIP using `node-zip`."},"warnings":[{"fix":"Migrate to actively maintained alternatives such as `jszip` (for browser and Node.js), `adm-zip` (Node.js, synchronous), or `zip-stream`/`archiver` (Node.js, streaming for large files).","message":"This package is explicitly abandoned and has not received updates since 2015. It lacks modern features, performance optimizations (like streaming for large files), and security patches, making it unsuitable for new projects and risky for existing ones.","severity":"breaking","affected_versions":">=1.1.1"},{"fix":"Ensure `fs.writeFileSync('file.zip', data, 'binary');` is used. Do not rely on default string encodings.","message":"When writing generated ZIP data to a file using Node.js's `fs.writeFileSync`, it is critical to specify `'binary'` encoding. Failing to do so can corrupt the ZIP archive, rendering it unreadable.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `const Zip = require('node-zip');` to import the library. If your project is ESM-only, you may need a wrapper or to transition to a modern, ESM-compatible zip library.","message":"Due to its age and lack of maintenance, `node-zip` does not support ES Modules (ESM) and must be imported using CommonJS `require()`. Attempting to `import` it will result in errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For large files, use streaming-based libraries (e.g., `zip-stream`, `unzipper`) which process data in chunks to conserve memory and avoid blocking. If you must use `node-zip`, process smaller files only.","message":"Older, non-streaming zip libraries like `node-zip` can lead to 'JavaScript heap out of memory' errors or block the Node.js event loop when processing large ZIP files, as they often load the entire archive into memory.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Immediately migrate to a well-maintained and actively supported zip library that has a track record of addressing security concerns.","message":"The library is unmaintained and will not receive security updates for known vulnerabilities (e.g., zip bombs, path traversal attacks). Using it in production could expose your application to security risks.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"If your project is ES Module-based, you must use `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const Zip = require('node-zip');`. However, migrating to a modern, ESM-compatible zip library is highly recommended.","cause":"Attempting to use `require()` in an ES Module context when `node-zip` is a CommonJS module.","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"The primary export of `node-zip` is a constructor function. It must be instantiated with `new`: `const Zip = require('node-zip'); const zipInstance = new Zip();`.","cause":"Calling `require('node-zip')` directly without the `new` keyword, or incorrectly trying to access named exports.","error":"TypeError: Zip is not a constructor"},{"fix":"Ensure that when writing the ZIP buffer to a file, `fs.writeFileSync` uses the `'binary'` encoding: `fs.writeFileSync('output.zip', data, 'binary');`. Also verify the integrity of the input ZIP file.","cause":"This error typically occurs during decompression if the input ZIP data is corrupted or if the data was written to disk using an incorrect encoding (e.g., UTF-8 instead of binary).","error":"Error: incorrect data size (decompression)"},{"fix":"Consider `node-zip` unsuitable for large files. Migrate to streaming-based zip libraries (e.g., `unzipper`, `zip-stream`) for efficient memory management when handling large archives.","cause":"Processing very large ZIP files or archives with many entries without streaming, causing the Node.js process to exceed its allocated memory limit.","error":"FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory"}],"ecosystem":"npm"}