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

convert-pino-request-to-curl

v1.0.11

Published

Convert Pino HTTP request logs to executable cURL commands with field anonymization support

Downloads

10,426

Readme

Convert Pino Request to cURL

npm version License: MIT

A lightweight TypeScript library that converts Pino HTTP request logs into ready-to-use cURL commands. Perfect for debugging, testing, and documentation purposes.

🚀 Installation

npm install convert-pino-request-to-curl
# or
yarn add convert-pino-request-to-curl
# or
pnpm add convert-pino-request-to-curl

📖 Usage

Basic Usage with Pino-HTTP

import { pinoHttp } from 'pino-http';
import { pino } from 'pino';
import { PinoRequestConverter } from 'convert-pino-request-to-curl';

const logger = pinoHttp({
  serializers: {
    err: pino.stdSerializers.err,
    req: (req) => {
      return {
        method: req.method,
        url: req.url,
        // Generate cURL command from request
        curl: PinoRequestConverter.getCurl(req),
      };
    },
    res: pino.stdSerializers.res,
  },
});

Anonymizing Sensitive Fields

Protect sensitive data by anonymizing specific fields in the request body:

// Using array (backwards compatible)
const curl = PinoRequestConverter.getCurl(req, ['password', 'token', 'apiKey']);

// Using options object (recommended)
const curl = PinoRequestConverter.getCurl(req, {
  anonymizedFields: ['password', 'token', 'apiKey'],
});

Input:

{
  "login": "admin",
  "password": "secret123",
  "token": "abc-def-ghi"
}

Output:

{
  "login": "admin",
  "password": "******",
  "token": "******"
}

Advanced Options

import { PinoRequestConverter, CurlOptions } from 'convert-pino-request-to-curl';

const options: CurlOptions = {
  // Fields to anonymize (replaces values with "******")
  anonymizedFields: ['password', 'token', 'secret'],
  
  // Headers to exclude from curl command
  excludeHeaders: ['content-length', 'user-agent'],
  
  // Add verbose output (-v flag)
  verbose: true,
  
  // Add compressed flag (--compressed)
  compressed: true,
  
  // Set maximum time for request (--max-time)
  maxTime: 30,
};

const curl = PinoRequestConverter.getCurl(req, options);

📋 Examples

GET Request

const request = {
  method: 'GET',
  url: '/api/users?page=1&limit=10',
  headers: {
    'host': 'api.example.com',
    'authorization': 'Bearer token123',
    'accept': 'application/json',
  },
  raw: {
    protocol: 'https',
    body: {},
  },
  // ... other fields
};

const curl = PinoRequestConverter.getCurl(request, {
  anonymizedFields: ['authorization'],
});

Generated cURL:

curl --location -g --request GET 'https://api.example.com/api/users?page=1&limit=10' \
--header 'host: api.example.com' \
--header 'authorization: ******' \
--header 'accept: application/json'

POST Request with Body

const request = {
  method: 'POST',
  url: '/api/login',
  headers: {
    'host': 'api.example.com',
    'content-type': 'application/json',
  },
  raw: {
    protocol: 'https',
    body: {
      email: '[email protected]',
      password: 'mypassword',
    },
  },
  // ... other fields
};

const curl = PinoRequestConverter.getCurl(request, {
  anonymizedFields: ['password'],
  compressed: true,
});

Generated cURL:

curl --location -g --compressed --request POST 'https://api.example.com/api/login' \
--header 'host: api.example.com' \
--header 'content-type: application/json' \
--data-raw '{"email":"[email protected]","password":"******"}'

Route Parameters

const request = {
  method: 'GET',
  url: '/api/users/:id/posts/:postId',
  params: {
    id: '123',
    postId: '456',
  },
  // ... other fields
};

const curl = PinoRequestConverter.getCurl(request);

Generated cURL:

curl --location -g --request GET 'https://api.example.com/api/users/id/123/posts/postId/456' \
--header 'host: api.example.com'

🔧 Configuration Options

CurlOptions Interface

| Option | Type | Default | Description | |--------|------|---------|-------------| | anonymizedFields | readonly string[] | [] | Fields to anonymize in request body (replaced with "******") | | excludeHeaders | readonly string[] | ['content-length'] | Headers to exclude from the cURL command | | verbose | boolean | false | Include verbose output (-v flag) | | compressed | boolean | false | Include compressed flag (--compressed) | | maxTime | number | undefined | Maximum time in seconds for the request (--max-time) |

🎯 Use Cases

  • Debugging: Quickly reproduce API requests from logs
  • Testing: Generate test requests for API endpoints
  • Documentation: Create example cURL commands for API docs
  • Monitoring: Track and replay requests in production
  • Development: Share reproducible requests with team members

🛡️ Security

The library automatically:

  • Removes content-length header by default (can be customized)
  • Supports anonymization of sensitive fields like passwords, tokens, etc.
  • Handles various data types (strings, numbers, booleans) in anonymization

📝 TypeScript Support

Full TypeScript support with comprehensive type definitions:

import { 
  PinoRequestConverter, 
  RequestType, 
  CurlOptions,
  RawRequest 
} from 'convert-pino-request-to-curl';

🧪 Testing

npm test

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT License

👨‍💻 Author

Mike Lima

🔗 Links

📊 Changelog

v1.0.10

  • ✨ Added comprehensive TypeScript interfaces
  • ✨ Added CurlOptions for advanced configuration
  • ✨ Support for verbose, compressed, and max-time options
  • ✨ Improved anonymization (supports numbers and booleans)
  • ✨ Better error handling and validation
  • ✨ Expanded test coverage
  • 📚 Enhanced documentation

v1.0.9

  • 🐛 Fixed module resolution issues

Star ⭐ this repository if you find it helpful!