Convert SRT to VTT from Node.js using the native fetch and FormData APIs — no dependencies, no SDK. Node 18+ ships both, so this is the lowest-friction path for serverless functions, API routes, or any JavaScript backend.
Pick Node.js when your app is already JavaScript end to end (Express, Fastify, Vercel functions) and you want the converted file to stay in the same language as the rest of your stack.
Convert SRT to VTT
const fs = require("node:fs");
const API_URL = "https://api.example.com/api/v1/convert";
const API_KEY = process.env.SUBTOVTT_API_KEY;
async function convertSrtToVtt() {
const form = new FormData();
form.append("file", new Blob([fs.readFileSync("movie.srt")]), "movie.srt");
form.append("from", "srt");
form.append("to", "vtt");
const response = await fetch(API_URL, {
method: "POST",
headers: { Authorization: `Bearer ${API_KEY}` },
body: form,
});
if (!response.ok) {
throw new Error(
`Conversion failed: ${response.status} ${await response.text()}`,
);
}
console.log("Cues:", response.headers.get("x-cue-count"));
fs.writeFileSync("movie.vtt", Buffer.from(await response.arrayBuffer()));
}
convertSrtToVtt().catch(console.error);
Set SUBTOVTT_API_KEY in your environment before running (100 free credits on key creation). The converted file is returned as the response body; here it's written straight to movie.vtt.
The x-cue-count response header reports how many cues the converter wrote. To apply formatting or timing fixes during the conversion, append fields like shift_ms or casing to the FormData.
Note: a failed request surfaces as
!response.ok— logawait response.text()to see the API's error message. Confirm Node 18+ if you seeFormData is not defined.
Convert between any formats
- Convert SRT to VTT →
- Convert VTT to SRT →
- Convert ASS to SRT →
- Convert SRT to ASS →
- Convert ASS to VTT →
- Convert VTT to ASS →
- Convert SRT to TXT →
Next
- Convert SRT to VTT with Python →
- Convert SRT to VTT in the browser →
- Authentication →
- Full API reference →