apiforge-analyzer
v1.2.1
Published
Universal API documentation generator for Express, Next.js, Vite, React Router, and Node.js
Readme
APIForge Analyzer
Universal API documentation generator for Express, Next.js, Vite, React Router, and Node.js.
Supports both ESM (import) and CommonJS (require).
📦 Installation
npm install apiforge-analyzer🚀 Quick Start
Express (CommonJS)
const express = require('express')
const { analyze } = require('apiforge-analyzer')
const app = express()
app.get('/api/users', (req, res) => res.json({ users: [] }))
app.post('/api/users', (req, res) => res.json({ created: true }))
analyze(app, {
projectName: 'My API',
apiKey: process.env.APIFORGE_KEY,
upload: true
})
app.listen(3000)Express (ESM)
import express from 'express'
import { analyze } from 'apiforge-analyzer'
const app = express()
app.get('/api/users', (req, res) => res.json({ users: [] }))
await analyze(app, {
projectName: 'My API',
apiKey: process.env.APIFORGE_KEY
})
app.listen(3000)Next.js Pages Router
// pages/api/analyze.ts
import { analyzeNextPages } from 'apiforge-analyzer'
export default async function handler(req, res) {
await analyzeNextPages({
projectName: 'My Next.js API',
apiKey: process.env.APIFORGE_KEY,
upload: true
})
res.json({ success: true })
}Next.js App Router
// app/api/analyze/route.ts
import { analyzeNextApp } from 'apiforge-analyzer'
export async function GET() {
await analyzeNextApp({
projectName: 'My Next.js API',
apiKey: process.env.APIFORGE_KEY,
upload: true
})
return Response.json({ success: true })
}Vite
// vite-analyze.js
import { analyzeVite } from 'apiforge-analyzer'
// Analyzes proxy routes in vite.config.js
await analyzeVite({
projectName: 'My Vite App',
apiKey: process.env.APIFORGE_KEY,
upload: true
})Example Vite Config:
// vite.config.js
export default {
server: {
proxy: {
'/api': 'http://localhost:3000',
'/auth': 'http://localhost:3001'
}
}
}React Router
// analyze-routes.js
import { analyzeReactRouter } from 'apiforge-analyzer'
// Analyzes routes from src/routes.tsx
await analyzeReactRouter({
projectName: 'My React App',
apiKey: process.env.APIFORGE_KEY,
upload: true
})Example Routes File:
// src/routes.tsx
import { createBrowserRouter } from 'react-router-dom'
export const router = createBrowserRouter([
{ path: '/', element: <Home /> },
{ path: '/users/:id', element: <UserDetail /> },
{ path: '/about', element: <About /> }
])⚙️ Configuration
Options
interface AnalyzerOptions {
// Required
projectName: string // Name of your project
// Optional
baseUrl?: string // Base URL of your API
apiKey?: string // APIForge API key
apiForgeUrl?: string // APIForge server URL (default: http://localhost:3000)
upload?: boolean // Upload to APIForge (default: true if apiKey provided)
saveJson?: boolean // Save routes to JSON file
jsonPath?: string // Path for JSON file (default: api-export.json)
framework?: string // Force framework detection
nextDir?: string // Next.js directory or config file path
skipInProduction?: boolean // Skip in production (default: true)
}Environment Variables
APIFORGE_KEY=your-api-key
APIFORGE_URL=http://localhost:3000 # or https://apiforge.dev
NODE_ENV=development # Analysis skipped if production📚 Framework Support
| Framework | Status | Import |
|-----------|--------|--------|
| Express | ✅ Full | analyzeExpress or analyze |
| Next.js Pages | ✅ Full | analyzeNextPages |
| Next.js App Router | ✅ Full | analyzeNextApp |
| Vite | ✅ Full | analyzeVite |
| React Router | ✅ Full | analyzeReactRouter |
📖 Examples
Export to JSON Only
import { analyze } from 'apiforge-analyzer'
await analyze(app, {
projectName: 'My API',
saveJson: true,
jsonPath: './docs/api.json',
upload: false // Don't upload
})Auto-Detection
// Framework is auto-detected
import { analyze } from 'apiforge-analyzer'
await analyze(app, { projectName: 'My API' })Custom Config Paths
// Vite with custom config
await analyzeVite({
projectName: 'My App',
nextDir: 'vite.config.ts' // Custom path
})
// React Router with custom routes file
await analyzeReactRouter({
projectName: 'My App',
nextDir: 'src/app/routes.tsx' // Custom path
})Skip in Production
// Automatically skips if NODE_ENV=production
await analyze(app, {
projectName: 'My API',
skipInProduction: true // Default
})🔑 Getting an API Key
- Sign up at APIForge
- Go to Dashboard → API Keys
- Generate a new key
- Set
APIFORGE_KEY=your-keyin.env
🛠️ Module Support
This package supports both ESM and CommonJS:
// ESM
import { analyze } from 'apiforge-analyzer'
// CommonJS
const { analyze } = require('apiforge-analyzer')
// Default import (CommonJS)
const apiforge = require('apiforge-analyzer').default📝 What Gets Analyzed
- ✅ Route paths
- ✅ HTTP methods (GET, POST, PUT, DELETE, etc.)
- ✅ Path parameters (
:id,:userId) - ✅ Middleware names
- ✅ Route tags/groups
- ✅ Response codes
- ✅ Proxy configurations (Vite)
- ✅ Frontend routes (React Router)
🧪 Testing Locally
See NPM_LINK_TEST.md for detailed testing instructions using npm link.
🤝 Contributing
Pull requests welcome! Please see CONTRIBUTING.md.
📄 License
MIT © APIForge
Made with ❤️ by the APIForge team
