A powerful npm package that automatically captures API requests from your Express backend and converts them into Postman Collections. Streamline your API testing workflow by automatically generating Postman collections from live API traffic.
Automatic API Capture - Middleware that intercepts and logs all incoming API requests
Request Deduplication - Intelligently deduplicates requests based on method and path
Postman Export - Convert captured requests to standard Postman Collection format
CLI Tool - Easy-to-use command-line interface for exporting collections
Colored Output - User-friendly colored terminal output for better readability
Configurable - Customize output filename and file paths
npm install postman-simplifiedTo use the postman-simplified CLI command globally:
npm install -g postman-simplified
# or
npm linkModule Type
import express from 'express';
import { requestInterceptor } from 'postman-simplified';
const app = express();
// Add the request interceptor middleware
app.use(express.json());
app.use(requestInterceptor());
// Your routes here
app.get('/api/users', (req, res) => {
res.json({ users: [] });
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});CommonJS
const express = require('express');
const { requestInterceptor } = require('postman-simplified');
const app = express();
// Add the request interceptor middleware
app.use(express.json());
app.use(requestInterceptor());
// Your routes here
app.get('/api/users', (req, res) => {
res.json({ users: [] });
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});Make requests to your API using any HTTP client:
npm run dev
#or
npm run startThe interceptor will automatically capture all API requests and save them to api_history.json.
Use the CLI to convert your captured API history to a Postman collection:
postman-simplified export api_history.jsonOr specify a custom output filename:
postman-simplified export api_history.json -o my_collection.postman_jsonThis generates a Postman Collection file that you can import directly into Postman.
Express middleware that captures incoming API requests and logs them to a JSON file.
Parameters:
options(Object, optional)filePath(String): Path to save the API history. Default:'api_history.json'
Returns: Express middleware function
Example:
import { requestInterceptor } from 'postman-simplified';
app.use(requestInterceptor({ filePath: 'my_api_history.json' }));Converts a captured API history JSON file to a Postman collection.
Usage:
postman-simplified export <input> -o [options]Arguments:
<input>- Path to the captured JSON file generated by the request interceptor
Options:
-o, --output <filename>- Custom output filename (default:collection.postman_json)
Examples:
# Basic export
postman-simplified export api_history.json
# Export with custom output name
postman-simplified export api_history.json -o my_apis.postman_json- Request Capture: The
requestInterceptormiddleware automatically captures every incoming HTTP request - Deduplication: Duplicate requests (same method and path) are intelligently deduplicated, keeping requests with request bodies when available
- JSON Storage: All captured requests are stored in a JSON file (default:
api_history.json) - Postman Conversion: The CLI tool reads the JSON file and converts it to Postman Collection v2.1.0 format
- Import to Postman: The generated collection can be imported into Postman for testing
[
{
"method": "GET",
"path": "/api/users",
"headers": {
"content-type": "application/json",
"user-agent": "Mozilla/5.0..."
},
"body": null,
"time": "2024-05-02T10:30:00.000Z"
},
{
"method": "POST",
"path": "/api/users",
"headers": {
"content-type": "application/json"
},
"body": {
"name": "John Doe",
"email": "john@example.com"
},
"time": "2024-05-02T10:31:00.000Z"
}
]The generated collection includes:
- Collection Info - Metadata and schema reference
- Requests - Organized with method and path as names
- Headers - All captured headers from original requests
- Body - Request payloads formatted as JSON
- URL Templates - Uses
{{baseUrl}}variable for easy configuration
{
"info": {
"name": "Postman Simplified | Auto-Generated API Collection",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "GET /api/users",
"request": {
"method": "GET",
"header": [...],
"url": {
"raw": "{{baseUrl}}/api/users",
"host": ["{{baseUrl}}"],
"path": ["api", "users"]
}
}
}
]
}# Start development server with auto-reload
npm run dev
# Start production server
npm start
# Run tests
npm test- express - Web framework for Node.js
- commander - CLI argument parsing
- chalk - Colored terminal output
- dotenv - Environment variable management
- nodemon - Development server with auto-reload
- Node.js 16.0 or higher
- npm 7.0 or higher
- API Testing - Capture real API traffic and test against it in Postman
- Documentation - Generate API collections for team documentation
- Testing - Create comprehensive test suites from live API interactions
- API Development - Build collections while developing backend APIs
- Quality Assurance - Verify all API endpoints are working correctly
Solution: Ensure the input file path is correct and the file exists:
postman-simplified export ./path/to/api_history.jsonSolution: The interceptor only captures requests made after the middleware is applied. Ensure you add the middleware before defining your routes.
Solution: The interceptor skips duplicate GET requests by design. If you need to capture all GET requests, modify the deduplication logic in requestInterceptor.js.
app.use(requestInterceptor({ filePath: './logs/my_history.json' }));Backend to Postman Project
├── .gitignore # Files to be ignored by git
├── .npmignore # Files to be ignored by npm while publishing to npmjs
├── cli.js # Terminal based options code - Chalk, Commander
├── index.js # Entry Point
├── LICENSE # Project License
├── package-lock.json
├── package.json
├── postman-mapper.js # Converts to postman readable format
├── Readme.md # Project Readme
├── requestInterceptor.js # Middleware to be injected , handles the requests formatting to json
└── server.js # Sample usageContributions are welcome! Please feel free to submit a pull request.
MIT
Pranava Pai N
Github: Pranava Pai N
For issues, feature requests, or questions, please create an issue in the repository.
Happy API Testing!