Convert Pino HTTP request logs to executable cURL commands with field anonymization support
npm install convert-pino-request-to-curl

A lightweight TypeScript library that converts Pino HTTP request logs into ready-to-use cURL commands. Perfect for debugging, testing, and documentation purposes.
``bash`
npm install convert-pino-request-to-curlor
yarn add convert-pino-request-to-curlor
pnpm add convert-pino-request-to-curl
`typescript
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,
},
});
`
Protect sensitive data by anonymizing specific fields in the request body:
`typescript
// 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:
`json`
{
"login": "admin",
"password": "secret123",
"token": "abc-def-ghi"
}
Output:
`json`
{
"login": "admin",
"password": "",
"token": ""
}
`typescript
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);
`
`typescript
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:
`bash`
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'
`typescript
const request = {
method: 'POST',
url: '/api/login',
headers: {
'host': 'api.example.com',
'content-type': 'application/json',
},
raw: {
protocol: 'https',
body: {
email: 'user@example.com',
password: 'mypassword',
},
},
// ... other fields
};
const curl = PinoRequestConverter.getCurl(request, {
anonymizedFields: ['password'],
compressed: true,
});
`
Generated cURL:
`bash`
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":"user@example.com","password":""}'
`typescript
const request = {
method: 'GET',
url: '/api/users/:id/posts/:postId',
params: {
id: '123',
postId: '456',
},
// ... other fields
};
const curl = PinoRequestConverter.getCurl(request);
`
Generated cURL:
`bash`
curl --location -g --request GET 'https://api.example.com/api/users/id/123/posts/postId/456' \
--header 'host: api.example.com'
| 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) |
- 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
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
Full TypeScript support with comprehensive type definitions:
`typescript`
import {
PinoRequestConverter,
RequestType,
CurlOptions,
RawRequest
} from 'convert-pino-request-to-curl';
`bash`
npm test
Contributions are welcome! Please feel free to submit a Pull Request.
Mike Lima
- GitHub: @mikemajesty
- Email: mike.rodrigues.lima@gmail.com
- npm Package
- GitHub Repository
- Issues
---
Star โญ this repository if you find it helpful!