Skip to content

stackblitz-labs/stackblitz.zip

Repository files navigation

stackblitz-zip

Download StackBlitz projects programmatically

npm version npm downloads Github Actions Codecov

❓ Why?

While StackBlitz provides an API to fetch project data, there's no built-in way to download projects as zip files programmatically. This tool makes it easy to download reproductions for issues quickly.

Important

This project is not affiliated with or endorsed by StackBlitz in any way. Users are responsible for ensuring their use of this tool complies with StackBlitz's Terms of Service. Please review their terms before using this tool.

🌐 stackblitz.zip

The easiest way to download a StackBlitz project is at stackblitz.zip

Simply replace stackblitz.com with stackblitz.zip in any StackBlitz edit URL:

Original:  https://stackblitz.com/edit/nuxt-starter-k7spa3r4
Download:  https://stackblitz.zip/edit/nuxt-starter-k7spa3r4

Features

  • πŸ”“ No authentication or API keys required!
  • βš—οΈ Built on Nitro
  • β–² Deployed on Vercel

πŸ‘‰ see source

CLI

# download a project as a zip file
npx stackblitz-zip https://stackblitz.com/edit/nuxt-starter-k7spa3r4

# specify output path for zip
npx stackblitz-zip https://stackblitz.com/edit/nuxt-starter-k7spa3r4 my-project.zip

# clone project to a directory
npx stackblitz-clone https://stackblitz.com/edit/nuxt-starter-k7spa3r4

# clone to a specific directory
npx stackblitz-clone https://stackblitz.com/edit/nuxt-starter-k7spa3r4 ./my-project

Programmatic Usage

Install the package:

npm install stackblitz-zip

Node.js

import { cloneProject, downloadToFile, parseUrl } from 'stackblitz-zip'

// download from a URL as a zip file
const projectId = parseUrl('https://stackblitz.com/edit/nuxt-starter-k7spa3r4')
await downloadToFile({ projectId, outputPath: './output.zip' })

// download by project ID
await downloadToFile({
  projectId: 'nuxt-starter-k7spa3r4',
  outputPath: './my-project.zip',
})

// clone project to a directory
await cloneProject({
  projectId: 'nuxt-starter-k7spa3r4',
  outputPath: './my-project',
})

Web APIs

import { downloadToBlob, downloadToResponse, parseUrl } from 'stackblitz-zip'

// download as Web Response (edge runtimes, servers)
const projectId = parseUrl('https://stackblitz.com/edit/nuxt-starter-k7spa3r4')
const response = await downloadToResponse({ projectId })
// response can be returned directly from edge functions

// or download as Blob (browser-friendly)
const blob = await downloadToBlob({ projectId })

// trigger browser download
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = `${projectId}.zip`
a.click()
URL.revokeObjectURL(url)

Note

Direct browser usage may be blocked by CORS when fetching from stackblitz.com.

Features

  • Universal - works in Node.js, browsers, and edge runtimes
  • Built with tsdown and client-zip
  • Nitro web service at stackblitz.zip
  • Fetches project data directly from StackBlitz API
  • Zip slip protection and security validations
  • Configurable size limits and timeouts
  • Web API streaming (Response/ArrayBuffer/Blob)

Note

The APIs use Web standards (fetch, ArrayBuffer, Blob) but direct fetching from stackblitz.com may be blocked by CORS.

Security

  • βœ… Zip slip protection - file paths are sanitized to prevent directory traversal
  • βœ… Size limits - configurable limits on file size (10MB) and total size (100MB)
  • βœ… Request timeout - prevents hanging requests (30s default)
  • βœ… Project ID validation - only alphanumeric, hyphens, and underscores
  • βœ… Memory efficient - streaming support with no temporary files

Self-Hosting

Self-host the web service using the included Nitro app:

cd app
pnpm install
pnpm build
pnpm preview

Deploy to any platform using Nitro's deployment presets - supports Vercel, Netlify, Cloudflare Pages, AWS, Azure, Node.js, and many more.

API

downloadToFile(options: DownloadOptions): Promise<string>

Downloads a StackBlitz project and returns the path to the created zip file.

Options:

  • projectId (string, required): The StackBlitz project ID
  • outputPath (string, optional): Path where the zip file should be saved. Defaults to <project-id>.zip
  • timeout (number, optional): Timeout in milliseconds for loading the project. Defaults to 30000 (30 seconds)
  • maxFileSize (number, optional): Maximum size per file in bytes. Defaults to 10485760 (10MB)
  • maxTotalSize (number, optional): Maximum total project size in bytes. Defaults to 104857600 (100MB)
  • verbose (boolean, optional): Enable console logging. Defaults to false

cloneProject(options: CloneOptions): Promise<string>

Clones a StackBlitz project by creating all files in a target directory.

Options:

  • projectId (string, required): The StackBlitz project ID
  • outputPath (string, optional): Path where the project directory should be created. Defaults to <project-id>/
  • timeout (number, optional): Timeout in milliseconds for loading the project. Defaults to 30000 (30 seconds)
  • maxFileSize (number, optional): Maximum size per file in bytes. Defaults to 10485760 (10MB)
  • maxTotalSize (number, optional): Maximum total project size in bytes. Defaults to 104857600 (100MB)
  • verbose (boolean, optional): Enable console logging. Defaults to false

Returns: Path to the created directory

downloadToResponse(options): Promise<Response>

Downloads a StackBlitz project and returns it as a Web Response (universal).

Options: Same as downloadToFile except outputPath

Returns: A Response object containing the zip file stream

downloadToBuffer(options): Promise<ArrayBuffer>

Downloads a StackBlitz project and returns it as an ArrayBuffer (universal).

Options: Same as downloadToFile except outputPath

downloadToBlob(options): Promise<Blob>

Downloads a StackBlitz project and returns it as a Blob (browser-friendly).

Options: Same as downloadToFile except outputPath

parseUrl(url: string): string

Parse a StackBlitz URL and extract the project ID.

Parameters:

  • url (string, required): Full StackBlitz project URL (e.g., https://stackblitz.com/edit/project-id)

Returns: The project ID

Development

# clone this repository
git clone https://github.com/stackblitz-labs/stackblitz.zip

# install dependencies
corepack enable
pnpm install

# run interactive tests
pnpm dev

# build for production
pnpm build

License

Made with ❀️

Published under MIT License.

About

Download StackBlitz projects programmatically

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 3

  •  
  •  
  •