### Install Markitdown Server Dependencies Source: https://github.com/demomacro/markitdown-server/blob/master/README.md Clone the repository and install project dependencies using pnpm. Ensure you have Node.js and pnpm installed. ```bash # Clone the repository $ git clone https://github.com/DemoMacro/markitdown-server.git $ cd markitdown-server # Install dependencies $ pnpm install # Setup environment $ cp .env.example .env ``` -------------------------------- ### Build and Start Markitdown Server for Production Source: https://github.com/demomacro/markitdown-server/blob/master/README.md Commands to build the project for production and then start or stop the production server. ```bash # Build for production $ pnpm build # Start production server $ pnpm start # Stop production server $ pnpm stop ``` -------------------------------- ### Start Markitdown Server for Development Source: https://github.com/demomacro/markitdown-server/blob/master/README.md Run this command to start the development server. The server will be accessible at http://localhost:3000. ```bash # Start development server $ pnpm dev # Server starts at http://localhost:3000 ``` -------------------------------- ### Nitro Server Configuration Source: https://context7.com/demomacro/markitdown-server/llms.txt Example Nitro framework configuration for the server runtime, storage, and TypeScript settings. ```APIDOC ## Nitro Server Configuration ```typescript // nitro.config.ts import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({ preset: "node_cluster", // Uses Node.js cluster for multi-core support typescript: { strict: true, tsConfig: { compilerOptions: { strict: true, noEmit: true, }, }, }, runtimeConfig: { dockerImage: process.env.NITRO_DOCKER_IMAGE, // Docker image from env }, srcDir: "server", // Source directory for server code storage: { temp: { driver: "fs", base: "./.temp", // Temporary file storage location }, }, compatibilityDate: "2025-10-25", }); ``` ``` -------------------------------- ### JavaScript/TypeScript Client Usage Source: https://context7.com/demomacro/markitdown-server/llms.txt Examples of how to integrate with the Markitdown Server API using JavaScript and TypeScript, including file uploads and HTML string conversion. ```APIDOC ## JavaScript/TypeScript Client Usage ### Convert a file using FormData ```typescript async function convertDocument(file: File): Promise { const formData = new FormData(); formData.append("file", file); const response = await fetch("http://localhost:3000/api/convert", { method: "POST", body: formData, }); if (!response.ok) { throw new Error(`Conversion failed: ${response.status} ${response.statusText}`); } return await response.text(); } ``` ### Convert HTML string to Markdown ```typescript async function convertHtmlToMarkdown(htmlContent: string): Promise { const formData = new FormData(); const blob = new Blob([htmlContent], { type: "text/html" }); formData.append("file", blob, "content.html"); const response = await fetch("http://localhost:3000/api/convert", { method: "POST", body: formData, }); if (!response.ok) { const errorText = await response.text(); throw new Error(`Conversion failed: ${errorText}`); } return await response.text(); } // Usage example: const html = "

Hello World

This is a test.

"; const markdown = await convertHtmlToMarkdown(html); console.log(markdown); // Output: // # Hello World // // This is a test. ``` ``` -------------------------------- ### Convert Document to Markdown using curl Source: https://github.com/demomacro/markitdown-server/blob/master/README.md Example using curl to send a POST request with a file to the conversion API endpoint. ```bash # Using curl curl -X POST http://localhost:3000/api/convert \ -F "file=@document.pdf" ``` -------------------------------- ### Configure MarkItDown Docker Image Source: https://context7.com/demomacro/markitdown-server/llms.txt Set the Docker image for MarkItDown conversion using the `NITRO_DOCKER_IMAGE` environment variable. This example shows a default and a custom registry configuration. ```bash # .env file configuration NITRO_DOCKER_IMAGE=your-docker-registry/markitdown:latest # Example with custom registry NITRO_DOCKER_IMAGE=ghcr.io/microsoft/markitdown:latest ``` -------------------------------- ### PM2 Production Configuration for Markitdown Server Source: https://context7.com/demomacro/markitdown-server/llms.txt Configuration for deploying the Markitdown Server in production using PM2. This setup specifies the application name, port, Node.js arguments, script path, and environment variables for the production server. ```javascript // prod.config.mjs export const apps = [ { name: "markitdown-server", port: "3333", node_args: "-r dotenv/config", script: "./.output/server/index.mjs", env: { PORT: 3333, }, }, ]; // Start production server // $ pnpm build && pnpm start // Stop production server // $ pnpm stop ``` -------------------------------- ### Convert Document to Markdown using Fetch API Source: https://github.com/demomacro/markitdown-server/blob/master/README.md Example of using the fetch API to send a POST request with a file (multipart/form-data) to the conversion endpoint and retrieve the Markdown output. ```typescript // Using fetch API const response = await fetch("http://localhost:3000/api/convert", { method: "POST", body: formData, // multipart/form-data with file }); const markdown = await response.text(); console.log(markdown); ``` -------------------------------- ### Environment Configuration Source: https://context7.com/demomacro/markitdown-server/llms.txt Configuration details for setting up the Markitdown Server, including environment variables for Docker image. ```APIDOC ## Environment Configuration Configure the Docker image containing MarkItDown via environment variables. ```bash # .env file configuration NITRO_DOCKER_IMAGE=your-docker-registry/markitdown:latest # Example with custom registry NITRO_DOCKER_IMAGE=ghcr.io/microsoft/markitdown:latest ``` ``` -------------------------------- ### Nitro Server Configuration Source: https://context7.com/demomacro/markitdown-server/llms.txt This TypeScript configuration file (`nitro.config.ts`) sets up the Nitro server, including presets, TypeScript strictness, runtime configuration for the Docker image, source directory, and temporary file storage. ```typescript // nitro.config.ts import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({ preset: "node_cluster", // Uses Node.js cluster for multi-core support typescript: { strict: true, tsConfig: { compilerOptions: { strict: true, noEmit: true, }, }, }, runtimeConfig: { dockerImage: process.env.NITRO_DOCKER_IMAGE, // Docker image from env }, srcDir: "server", // Source directory for server code storage: { temp: { driver: "fs", base: "./.temp", // Temporary file storage location }, }, compatibilityDate: "2025-10-25", }); ``` -------------------------------- ### Configure Docker Image for Markitdown Server Source: https://github.com/demomacro/markitdown-server/blob/master/README.md Set the NITRO_DOCKER_IMAGE environment variable to specify the Docker image used by the Markitdown Server. This is a required configuration. ```bash # Docker image configuration (required) NITRO_DOCKER_IMAGE="your-docker-registry/markitdown:latest" ``` -------------------------------- ### Convert DOCX to Markdown using cURL Source: https://context7.com/demomacro/markitdown-server/llms.txt This cURL command demonstrates converting a Word document (DOCX) to Markdown. The server handles the conversion process. ```bash # Convert a Word document to Markdown curl -X POST http://localhost:3000/api/convert \ -F "file=@report.docx" ``` -------------------------------- ### Internal convertFile Utility Function Source: https://context7.com/demomacro/markitdown-server/llms.txt This TypeScript snippet shows the internal `convertFile` utility function, which handles file conversion via a Docker container. It manages temporary file storage and cleanup. ```typescript import { convertFile } from "~/utils/docker"; import { toUint8Array } from "undio"; // Internal usage within the server // Converts file buffer to Markdown via Docker container const fileBuffer = new Uint8Array([/* file bytes */]); const markdown = await convertFile(fileBuffer, "document.pdf"); // The function internally: // 1. Generates a unique temp file name with UUID // 2. Stores the file in .temp/ directory // 3. Executes: docker run --rm -i < "/path/to/temp/file" --keep-data-uris // 4. Returns stdout (Markdown content) // 5. Cleans up temp file in finally block ``` -------------------------------- ### Convert PDF to Markdown using cURL Source: https://context7.com/demomacro/markitdown-server/llms.txt Use this cURL command to convert a PDF document to Markdown via the /api/convert endpoint. Ensure the server is running locally. ```bash # Convert a PDF document to Markdown curl -X POST http://localhost:3000/api/convert \ -F "file=@document.pdf" ``` -------------------------------- ### Convert HTML to Markdown using cURL Source: https://context7.com/demomacro/markitdown-server/llms.txt Use this cURL command to convert an HTML file to Markdown. The server processes the uploaded file and returns Markdown content. ```bash # Convert an HTML file to Markdown curl -X POST http://localhost:3000/api/convert \ -F "file=@page.html" ``` -------------------------------- ### POST /api/convert - Document Conversion Endpoint Source: https://context7.com/demomacro/markitdown-server/llms.txt This endpoint accepts file uploads via multipart/form-data and converts them to Markdown format. It supports various document types like PDF, HTML, and DOCX. ```APIDOC ## POST /api/convert ### Description Converts uploaded documents to Markdown format. ### Method POST ### Endpoint /api/convert ### Parameters #### Request Body - **file** (file) - Required - The document file to convert. Accepts multipart/form-data. ### Request Example ```bash curl -X POST http://localhost:3000/api/convert \ -F "file=@document.pdf" ``` ### Response #### Success Response (200) - **Markdown Content** (string) - The converted content in plain text Markdown format. #### Response Example ```text # Document Title This is the converted content from your document. ## Section Header More converted text content... ``` ``` -------------------------------- ### Convert HTML String to Markdown using JavaScript Fetch API Source: https://context7.com/demomacro/markitdown-server/llms.txt This TypeScript function converts an HTML string to Markdown. It creates a Blob from the string and uploads it using the Fetch API. ```typescript // Convert HTML string to Markdown async function convertHtmlToMarkdown(htmlContent: string): Promise { const formData = new FormData(); const blob = new Blob([htmlContent], { type: "text/html" }); formData.append("file", blob, "content.html"); const response = await fetch("http://localhost:3000/api/convert", { method: "POST", body: formData, }); if (!response.ok) { const errorText = await response.text(); throw new Error(`Conversion failed: ${errorText}`); } return await response.text(); } // Usage example const html = "

Hello World

This is a test.

"; const markdown = await convertHtmlToMarkdown(html); console.log(markdown); // Output: // # Hello World // // This is a test. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.