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

nestjs-convert-to-curl

v2.0.7

Published

Nestjs convert Axios Error to CURL

Downloads

1,328

Readme

Convert Axios to cURL

A lightweight TypeScript utility to convert Axios requests and errors into cURL commands for debugging and logging purposes.

npm version License: MIT

Installation

npm install nestjs-convert-to-curl

Features

  • 🔄 Convert Axios requests to cURL commands
  • 🔒 Anonymize sensitive fields (passwords, tokens, etc.)
  • 📝 Support for all HTTP methods (GET, POST, PUT, PATCH, DELETE)
  • 🎯 Works with Axios errors and request configs
  • 🔍 Query parameters and headers support
  • 💾 Request body handling (JSON, strings, buffers)

Usage

Basic Example

import axios from 'axios';
import { AxiosConverter } from 'nestjs-convert-to-curl';

try {
  await axios.post('https://api.example.com/users', {
    name: 'John Doe',
    email: '[email protected]'
  });
} catch (error) {
  console.log(AxiosConverter.getCurl(error));
}

Output:

curl --location -g --request POST 'https://api.example.com/users' --header 'Content-Type: application/json' --data-raw '{"name":"John Doe","email":"[email protected]"}'

Anonymizing Sensitive Fields

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

import axios from 'axios';
import { AxiosConverter } from 'nestjs-convert-to-curl';

try {
  await axios.post('https://api.example.com/auth', {
    username: 'johndoe',
    password: 'secret123',
    apiKey: 'my-secret-key'
  }, {
    headers: { 
      'Authorization': 'Bearer token123' 
    }
  });
} catch (error) {
  // Anonymize password and apiKey fields
  console.log(AxiosConverter.getCurl(error, ['password', 'apiKey']));
}

Output:

curl --location -g --request POST 'https://api.example.com/auth' --header 'Content-Type: application/json' --header 'Authorization: Bearer token123' --data-raw '{"username":"johndoe","password":"******","apiKey":"******"}'

Nested Fields Anonymization

You can anonymize nested fields using dot notation:

import axios from 'axios';
import { AxiosConverter } from 'nestjs-convert-to-curl';

try {
  await axios.post('https://api.example.com/employees', {
    name: 'Mike',
    credentials: {
      password: '123456',
      ssn: '123-45-6789'
    }
  });
} catch (error) {
  console.log(AxiosConverter.getCurl(error, ['credentials.password', 'credentials.ssn']));
}

Output:

curl --location -g --request POST 'https://api.example.com/employees' --header 'Content-Type: application/json' --data-raw '{"name":"Mike","credentials":{"password":"******","ssn":"******"}}'

Using with Axios Config

You can also pass an Axios config object directly:

import { AxiosConverter } from 'nestjs-convert-to-curl';

const config = {
  method: 'GET',
  url: 'https://api.example.com/users',
  params: { page: 1, limit: 10 },
  headers: { 'Authorization': 'Bearer token' }
};

console.log(AxiosConverter.getCurl(config));

Output:

curl --location -g --request GET 'https://api.example.com/users?page=1&limit=10' --header 'Authorization: Bearer token'

API Reference

AxiosConverter.getCurl(request, anonymizedFields?)

Converts an Axios request or error to a cURL command.

Parameters:

  • request (required): Axios error object or request config
  • anonymizedFields (optional): Array of field names to anonymize (supports dot notation for nested fields)

Returns: String containing the formatted cURL command

Use Cases

  • 🐛 Debugging: Quickly reproduce API calls using cURL
  • 📊 Logging: Log failed requests in a readable format
  • 🔍 Monitoring: Track API calls for troubleshooting
  • 📝 Documentation: Generate cURL examples from your code
  • 🧪 Testing: Share reproducible API calls with your team

Contributing

Contributions are welcome! Feel free to submit issues and pull requests.

Contributors

License

This project is licensed under the MIT License.