Node.js guide

How to Parse a Resume in Node.js

Get data out of PDF and DOCX resumes with JavaScript: first with open-source packages, then with a resume parser API that returns structured JSON. Every snippet was run against a real file, and the outputs are what it printed. Prefer Python? See the Python version.

What you need

  • Node.js 18 or newer (the examples use ES modules: save them as .mjs)
  • npm install pdf-parse mammoth for step 1
  • A sample resume (PDF or DOCX)

1Extract the text from PDF and DOCX files

pdf-parse reads text-based PDFs and mammoth reads Word files. Importing pdf-parse/lib/pdf-parse.js directly avoids a debug mode in the package's entry file.

extract-text.mjs
import { readFile } from "node:fs/promises";
import pdf from "pdf-parse/lib/pdf-parse.js";
import mammoth from "mammoth";

async function extractText(path) {
  const buffer = await readFile(path);
  if (path.toLowerCase().endsWith(".pdf")) {
    return (await pdf(buffer)).text;
  }
  if (path.toLowerCase().endsWith(".docx")) {
    return (await mammoth.extractRawText({ buffer })).value;
  }
  throw new Error(`Unsupported file type: ${path}`);
}

const text = await extractText("resume.pdf");
console.log(text.slice(0, 300));
Maria Lopez
Senior Backend Engineer
San Francisco, CA | [email protected] | +1 415 555 0142
linkedin.com/in/marialopez-example | github.com/marialo

You get the words back, but not the structure: pdf-parse pads lines with spaces to mimic the page layout, columns can interleave, and nothing tells you which line is a job title and which is an employer.

2Pull out contact details with regular expressions

Fields with a predictable shape are easy to match:

extract-contact.mjs
const EMAIL = /[\w.+-]+@[\w-]+\.[\w.-]+/;
const PHONE = /\+?\d[\d\s().-]{7,}\d/;
const LINKEDIN = /linkedin\.com\/in\/[\w-]+/i;

function extractContact(text) {
  return {
    email: text.match(EMAIL)?.[0] ?? null,
    phone: text.match(PHONE)?.[0].trim() ?? null,
    linkedin: text.match(LINKEDIN)?.[0] ?? null,
  };
}

console.log(extractContact(text));
{
  email: '[email protected]',
  phone: '+1 415 555 0142',
  linkedin: 'linkedin.com/in/marialopez-example'
}

Work history, dates, education and skills have no fixed format, so regex stops being useful here. See how to build a resume parser for the options and their trade-offs.

3Get structured JSON from a resume parser API

For the full structure, send the file to the CV Parser Pro resume parser API. Create a free account to get an API key (10 free parses, no credit card) and set it as CVPP_API_KEY. This function uploads a file and waits for the result:

parse-resume.mjs
import { readFile } from "node:fs/promises";
import { basename } from "node:path";

const API = "https://cvparserpro.com/api/v1";
const headers = { "X-API-Key": process.env.CVPP_API_KEY };
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

async function parseResume(path, timeoutMs = 120_000) {
  const form = new FormData();
  form.append("files", new Blob([await readFile(path)]), basename(path));
  const upload = await fetch(`${API}/parse`, { method: "POST", headers, body: form });
  if (!upload.ok) throw new Error(`Upload failed: ${upload.status} ${await upload.text()}`);
  const { candidates } = await upload.json();

  const deadline = Date.now() + timeoutMs;
  while (Date.now() < deadline) {
    const res = await fetch(`${API}/candidates/${candidates[0].id}`, { headers });
    const { data } = await res.json();
    if (data.parsing_status === "completed") return data;
    if (data.parsing_status === "failed") throw new Error(JSON.stringify(data.parsing_errors));
    await sleep(3000);
  }
  throw new Error(`Resume ${candidates[0].id} was not parsed in time`);
}

const resume = await parseResume("resume.pdf");
console.log(`${resume.full_name} - ${resume.current_title}`);
for (const job of resume.work_history) {
  console.log(`${job.start_date} to ${job.end_date}: ${job.title} at ${job.company}`);
}
Maria Lopez - Senior Backend Engineer
2021-03 to present: Senior Backend Engineer at Northwind Logistics
2018-01 to 2021-02: Software Engineer at Brightline Health

Dates come back normalised to YYYY-MM. The response also has education, certifications, skills, spoken languages, a summary and per-field confidence scores; see every field in the response. If you would rather not poll, configure a webhook and receive a signed event when each resume is done.

4Parse a folder of resumes into a CSV

Add this below parseResume to turn a resumes/ folder into a spreadsheet:

batch-to-csv.mjs
import { readdir, writeFile } from "node:fs/promises";
import { extname, join } from "node:path";

const csv = (v) => `"${String(v ?? "").replace(/"/g, '""')}"`;
const rows = [["file", "name", "email", "title", "years", "skills"].join(",")];

for (const file of (await readdir("resumes")).sort()) {
  if (![".pdf", ".docx"].includes(extname(file).toLowerCase())) continue;
  try {
    const r = await parseResume(join("resumes", file));
    rows.push([file, r.full_name, r.email, r.current_title, r.years_of_experience, (r.skills ?? []).join(", ")].map(csv).join(","));
  } catch (err) {
    console.log(`${file}: ${err.message}`);
  }
}

await writeFile("candidates.csv", rows.join("\n") + "\n");
console.log(`Saved ${rows.length - 1} candidates to candidates.csv`);
file,name,email,title,years,skills
"maria.docx","Maria Lopez","[email protected]","Senior Backend Engineer","7","Python, Go, PostgreSQL, Kubernetes, AWS, Apache Kafka, Docker"
"maria.pdf","Maria Lopez","[email protected]","Senior Backend Engineer","7","Python, Go, PostgreSQL, Kubernetes, AWS, Apache Kafka, Docker"

Files that cannot be parsed are reported and skipped, and their credit is refunded. For large backlogs see bulk resume parsing.

Try the API on your own resumes

10 free parses. No credit card. No expiry.

Get a free API key

Frequently Asked Questions

pdf-parse reads text from text-based PDFs and mammoth reads DOCX files. Both return plain text, not structured fields, so you still need rules, a model or a parser API to get job history and skills.

No. Call it from your server or a serverless function. An API key in front-end code can be copied by anyone who opens the developer tools.

Yes. The API examples only use fetch, FormData and Blob, which are built into Node 18 and later. The text-extraction step needs the pdf-parse and mammoth packages.