{"library":"ripgrep","title":"ripgrep-node","description":"This `ripgrep` npm package provides the powerful command-line utility `ripgrep` in a fully cross-platform, dependency-free manner by compiling it to WebAssembly (WASM). As of version 0.3.1, it offers programmatic access to `ripgrep`'s core functionality, suitable for Node.js, Bun, Deno, and even bundler-friendly browser environments without requiring native binaries or post-install scripts. The package embeds the WASM module as a z85+brotli encoded string and leverages WASI for execution, defaulting to Node.js's built-in `node:wasi` for optimal performance when available. Its key differentiator is providing `ripgrep`'s capabilities entirely within the JavaScript ecosystem, making it a drop-in programmatic replacement for native `ripgrep` spawns, with the WASM module dynamically cached to the OS temp directory for subsequent fast access.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install ripgrep"],"cli":null},"imports":["import { ripgrep } from 'ripgrep';","import { rgPath } from 'ripgrep';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { ripgrep, rgPath } from \"ripgrep\";\nimport { spawn } from \"node:child_process\";\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\n// Create a dummy file for searching\nconst tempDir = fs.mkdtempSync(path.join(process.cwd(), 'rg-temp-'));\nconst filePath = path.join(tempDir, 'test.txt');\nfs.writeFileSync(filePath, 'This is a test with TODO item one.\\nAnother line with TODO item two.');\n\nasync function runRipgrep() {\n  console.log('--- Running ripgrep programmatically (buffer output) ---');\n  try {\n    const { code, stdout, stderr } = await ripgrep([\"TODO\", tempDir], { buffer: true });\n    console.log(`Exit Code: ${code}`);\n    console.log(`STDOUT:\\n${stdout}`);\n    console.log(`STDERR:\\n${stderr}`);\n  } catch (e) {\n    console.error('Error running ripgrep programmatically:', e);\n  }\n\n  console.log('\\n--- Spawning ripgrep as a child process ---');\n  try {\n    const child = spawn(rgPath, [\"TODO\", tempDir], { stdio: \"pipe\" });\n    child.stdout.pipe(process.stdout);\n    child.stderr.pipe(process.stderr);\n    child.on('close', (code) => {\n      console.log(`Child process exited with code ${code}`);\n      fs.rmSync(tempDir, { recursive: true, force: true }); // Clean up\n    });\n  } catch (e) {\n    console.error('Error spawning ripgrep:', e);\n    fs.rmSync(tempDir, { recursive: true, force: true }); // Clean up\n  }\n}\n\nrunRipgrep();","lang":"typescript","description":"Demonstrates programmatic usage of `ripgrep` to search a temporary file, capturing its output, and an alternative method using `rgPath` with `node:child_process.spawn`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}