Home / Guides / JavaScript & Electron

Follow an export to the disk.

Desktop apps built on Electron split one feature over three places: the page, a preload bridge and the main process. REP connects them by the names they share.

Where does “Export notes” go?

  1. Page → bridge

    A small API

    The page can only call what the preload script exposes.

  2. Between processes

    A named message

    The bridge sends a channel name the main process listens on.

  3. Main process

    The real work

    The handler formats the data and writes the file.

Ask about the export

Use our Notes example (six files) or any Electron app you may examine. Packaged apps keep their code in resources/app.asar; REP reads inside it, so there is nothing to unpack by hand.

Your coding agent

›Use REP to analyze the app in ./notes-example. Trace the Export notes button: the API the page calls, the IPC channel, the handler, and the file it writes. Cite files and lines.

Trace it

The page calls a small API

renderer.js
document.querySelector('#export').addEventListener('click', async () => {
  const file = await window.notesApi.saveCsv();
  status.textContent = `Saved to ${file}`;
});

The preload script turns it into a message

preload.js
contextBridge.exposeInMainWorld('notesApi', {
  list: () => ipcRenderer.invoke('notes:list'),
  saveCsv: () => ipcRenderer.invoke('notes:save-csv'),
});

The main process answers it

main.js
ipcMain.handle('notes:save-csv', () => {
  const file = path.join(app.getPath('documents'), 'notes-export.csv');
  fs.writeFileSync(file, toCsv(notes, ['id', 'title', 'created']));
  return file;
});

The channel name is the join: one invoke in the bridge, one handle in the main process. REP lists every exposed API, every channel and every handler, and pairs them, so the agent follows the feature instead of searching for words.

From the terminal

The same analysis runs without an agent and prints JSON you can keep:

Terminal
rep analyze-javascript-application ./notes-example --json

Read the writer

csv.js
function toCsv(rows, columns) {
  const head = columns.join(',');
  const body = rows.map((r) => columns.map((c) => cell(r[c])).join(','));
  return [head, ...body].join('\n') + '\n';
}

So the file starts with id,title,created, then one line per note; a title with a comma or a quote gets wrapped in quotes by cell.