Skip to main content

Express

Setup

Do not hardcode FLASH_MD_API_KEY into the code or send it to the client. Load it from environment variables (process.env) and keep it only in the server process.

Basic endpoint

Complete router with vavalidation and error handling

In a real app it is advisable to isolate the integration in its own router, vavalidate the mimetype with multer.fileFilter, and centralize the error mapping in a middleware instead of repeating it in each route.
Express’s error middleware is recognized because it declares 4 parameters (err, req, res, next), not 3. If your handler has only 3 parameters, Express treats it as normal middleware and will never catch errors.

Production

Timeouts with AbortSignal.timeout

Retries with exponential backoff

Retry only 429 and 5xx. A different 4xx (400, 401, 403, 413, 415, 422) indicates that the request must be corrected, not repeated.

Large files with BYOS (output_url)

When you convert large documents into a background job (queues, workers), avoid loading the entire Markdown into the memory of the Node process: ask API to upload it directly to your bucket with a pre-signed URL PUT.
If your app processes many documents in the background (for example with BullMQ), combine output_url with the retry pattern: the worker should retry only on 429/5xx, and mark the job as failed permanently on any other 4xx without re-queuing it.