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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@codenteam/pandoc-server

v1.0.0

Published

A lightweight REST API server for Pandoc document conversion

Readme

Pandoc Server

A lightweight REST API server for Pandoc document conversion.

🚀 Features

  • Multiple Output Formats: Text, blob (for downloads), and base64 encoding
  • File Upload Support: Convert uploaded files or direct content input
  • Binary & Text Handling: Automatic detection and appropriate formatting
  • Security: Input validation, sanitization, and security headers
  • Error Handling: Comprehensive error handling with detailed messages
  • Docker Support: Ready-to-deploy Docker configuration
  • Health Monitoring: Built-in health check and monitoring endpoints

Installation

Via npm (recommended)

npx @codenteam/pandoc-server

Via Docker

docker-compose up

Manual Installation

git clone https://github.com/codenteam/pandoc-server.git
cd pandoc-server
pnpm install # or npm
pnpm start # or npm

Usage

Start the server:

npx @codenteam/pandoc-server --port=3000

Convert documents via HTTP POST:

curl -X POST http://localhost:3000/convert \
  -F "[email protected]" \
  -F "to=pdf"

API Endpoints

  • POST /convert - Convert documents
  • GET /formats - Get supported formats
  • GET /health - Health check

POST /converter/convert

Convert documents using Pandoc with custom arguments.

Request Body (JSON):

{
  "args": ["--from", "markdown", "--to", "html"],
  "input": "# Hello World\nThis is markdown content",
  "outputFormat": "text",
  "filename": "output.html"
}

Request Body (Form Data for File Upload):

curl -X POST http://localhost:3000/converter/convert \
  -F "[email protected]" \
  -F 'args=["--from", "markdown", "--to", "pdf"]' \
  -F 'outputFormat=blob' \
  -F 'filename=document.pdf'

Parameters:

  • args (Array): Pandoc command line arguments
  • input (String): Direct content input (if no file)
  • outputFormat (String): text, blob, or base64
  • filename (String): Output filename

Response Formats:

Text Format (JSON):

{
  "content": "<html><body><h1>Hello World</h1></body></html>",
  "filename": "output.html",
  "mimeType": "text/html",
  "format": "text",
  "size": 45
}

Base64 Format (JSON):

{
  "content": "PGh0bWw+PGJvZHk+PGgxPkhlbGxvIFdvcmxkPC9oMT4=",
  "filename": "output.html",
  "mimeType": "text/html",
  "format": "base64",
  "size": 45
}

Blob Format: Returns raw binary/text data with appropriate Content-Type headers for direct download.

GET /converter/formats

List all supported Pandoc input and output formats.

Response:

{
  "input": ["markdown", "html", "docx", "..."],
  "output": ["html", "pdf", "docx", "..."]
}

GET /converter/version

Get the installed Pandoc version.

Response:

{
  "version": "pandoc 3.5"
}

GET /health

Health check endpoint.

Response:

{
  "status": "ok",
  "timestamp": "2024-01-01T12:00:00.000Z",
  "service": "pandoc-server"
}

🧪 Testing

Quick Test

# Start the server
pnpm start # or npm

# Run curl tests
./test.sh

# Or run Node.js tests
node test.js

Example Conversions

Markdown to HTML:

curl -X POST http://localhost:3000/converter/convert \
  -H "Content-Type: application/json" \
  -d '{
    "args": ["--from", "markdown", "--to", "html"],
    "input": "# Hello\n\nThis is **bold** text.",
    "outputFormat": "text"
  }'

Markdown to PDF (download):

curl -X POST http://localhost:3000/converter/convert \
  -H "Content-Type: application/json" \
  -d '{
    "args": ["--from", "markdown", "--to", "pdf"],
    "input": "# My Document\n\nContent here.",
    "outputFormat": "blob",
    "filename": "document.pdf"
  }' \
  --output document.pdf

⚙️ Configuration

Environment Variables

  • PORT - Server port (default: 3000)
  • NODE_ENV - Environment mode

Supported Formats

The server supports all Pandoc input and output formats including:

Common Input Formats:

  • markdown, html, docx, odt, rtf, epub, latex, rst

Common Output Formats:

  • html, pdf, docx, odt, epub, latex, rtf, plain

🔒 Security

  • Input validation and sanitization
  • File size limits
  • Dangerous argument detection
  • Security headers (Helmet.js)
  • CORS configuration
  • Rate limiting (in production with nginx)

Extra Security

ExpressJS rate limiting

If you don't use nginx, you can do expressjs rate limiting using:

// Add to package.json dependencies
"express-rate-limit": "^7.1.5"

// Add to server.js
import rateLimit from 'express-rate-limit';
app.use(rateLimit({ windowMs: 15 * 60 * 1000, max: 100 }));

Extra security headers

If you don't use a security layer (Firewall, LB, etc), you can add extra security headers using:

// Add to server.js
import helmet from 'helmet';
app.use(helmet({
  contentSecurityPolicy: false, // Configure based on needs
  crossOriginResourcePolicy: { policy: "cross-origin" }
}));

🚢 Production Deployment

With Docker Compose

# Production deployment with nginx proxy
docker-compose --profile production up -d

Environment Setup

  1. Install Pandoc on your system
  2. Set appropriate environment variables
  3. Configure reverse proxy (nginx/Apache)
  4. Set up monitoring and logging
  5. Configure backup for temporary files cleanup

📋 Requirements

  • Node.js >= 16
  • Pandoc >= 2.0 (installed on system)
  • Optional: Docker for containerized deployment

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

License

GPL-2.0 (same as Pandoc)