npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

har-to-mocks

v2.3.1

Published

Extract response from .har file and create JSON mocks for mock server.

Downloads

173

Readme

har-to-mocks

Extract response from .har file and create JSON mocks for mock server.

Version Downloads/week License

Install CLI

npm install -g har-to-mocks

or by npx

npx har-to-mocks [path to .har] [path mock/api folder] --dry-run

How does it work?

Inspect and filter requests in .har files

File can contain hundreds of requests so it's important to be able filter data. For filtering you can use flags:

  • (--url) for filtering by match in the url. Search is case sensitive and matches against the full URL including query parameters (e.g., --url=?q=search or --url=/api/search?id=123)
  • (-m, --method=GET --method=POST) for filter specific method. Supported: 'GET', 'POST', 'PUT', 'DELETE' and 'PATCH' methods. Default value is 'GET'.
  • (-t, --type=xhr) for filtering request type. Default value is 'xhr'

Video example: YouTube [email protected].

example:

$ har-to-mocks ./file.har --url=api/service  --method=GET

will display:

Filtered requests:

 Name          │ Method │ Path                        │ Query
 ──────────────┼────────┼─────────────────────────────┼──────
 userRoles     │ GET    │ /api/service/userRoles      │
 currentUserId │ GET    │ /api/service/currentUserId  │
 active        │ GET    │ /api/service/clients/active │

The Query column displays URL query parameters for easy identification of similar requests.

If output folder is not specified, mocks will not be written and no Status column is shown.

Interactive Mode

Use the --interactive (or -i) flag to manually select which endpoints to write:

$ har-to-mocks ./file.har ./mocks --interactive

In interactive mode:

  1. A checkbox list appears with all endpoints
  2. Response Preview: As you navigate with arrow keys, the JSON response of the focused endpoint is displayed below the list
  3. Endpoints that would be written by default are pre-selected
  4. After selection, a folder tree preview is shown
  5. You're asked to confirm before files are written

Keyboard shortcuts:

  • ↑/↓ - Navigate through endpoints (updates response preview)
  • Space - Toggle selection
  • a - Toggle all
  • i - Invert selection
  • Enter - Confirm selection

The response preview helps you distinguish between multiple responses from the same endpoint with different data - useful when duplicate routes return different responses and you need to choose the right one.

Extract data from .har to mock/api folder

The second argument should be path to mock's folder. Export structure is prepared for mocks-to-msw which helps with integration with MSW (Mock Service Worker) and connect-api-mocker.

WARNING: When second argument is defined cli will write files. To avoid unwanted overwrite use --dry-run flag to skip writing part of process.

When a target folder is specified, the Status column shows what will happen to each file:

  • create - File doesn't exist, will be created
  • update - File already exists, will be overwritten
  • skip - Duplicate endpoint, will be skipped (a later entry writes to the same file)

example:

$ har-to-mocks ./file.har ./mocks --url=api/service  --method=GET --dry-run

will display:

Filtered requests:

 Name          │ Method │ Path                        │ Query │ Status
 ──────────────┼────────┼─────────────────────────────┼───────┼───────
 userRoles     │ GET    │ /api/service/userRoles      │       │ create
 currentUserId │ GET    │ /api/service/currentUserId  │       │ create
 active        │ GET    │ /api/service/clients/active │       │ create

Folder tree which will be applied:

└─ mocks
   └─ api
      └─ service
         ├─ userRoles
         │  └─ GET.json
         ├─ currentUserId
         │  └─ GET.json
         └─ clients
            └─ active
               └─ GET.json

No files were written. If you want to write files remove the (--dry-run) flag.

If files already exist, the tree shows which will be updated:

Folder tree which will be applied:

└─ mocks
   └─ api
      └─ service
         ├─ userRoles
         │  └─ GET.json [UPDATE]
         ├─ currentUserId
         │  └─ GET.json
         └─ clients
            └─ active
               └─ GET.json [UPDATE]

When multiple requests share the same path and method (but have different query parameters), they would write to the same file. A helpful hint is displayed:

Note: Some endpoints have status "skip" because they share the same path and method.
The last occurrence will be written. To select specific endpoints, use interactive mode:

  har-to-mocks <file.har> <output-folder> --interactive

Development

Prerequisites

  • Node.js >= 18.0.0
  • npm >= 7.0.0

Tech Stack

This project uses modern JavaScript tooling:

  • Framework: @oclif/core v4 - Modern CLI framework
  • Module System: ES Modules (ESM)
  • Testing: Vitest with snapshot testing
  • TypeScript: NodeNext module resolution for ESM compatibility
  • Linting: ESLint with TypeScript support

Getting Started

  1. Clone the repository

  2. Install dependencies:

    npm install
  3. Build the project:

    npm run build
  4. Run the CLI locally:

    ./bin/dev [args]

Available Scripts

  • npm run build - Compile TypeScript to JavaScript
  • npm run lint - Run ESLint
  • npm run lint:fix - Fix ESLint issues automatically
  • npm test - Run tests in watch mode
  • npm run test:ci - Run tests once (for CI)
  • npm run test:ui - Open Vitest UI for interactive testing
  • npm run coverage - Generate test coverage report

Testing

The project maintains 100% test coverage with:

  • Unit tests using Vitest with snapshot assertions
  • Integration tests that verify CLI behavior end-to-end
  • Snapshot testing to catch unintended output changes

Run tests:

npm test

Generate coverage report:

npm run coverage