A small utility that writes a file after formatting the content with Prettier. The package simplifies the workflow of formatting code before saving it to disk. Current stable version is 3.0.3 (as of 2025). Release cadence is irregular with minor updates. Key differentiators: it integrates formatting and file writing into one call, supports prettier config resolution, and works with string or URL file paths. Breaking change in v3.0.0 removed the sync version, making it async-only. Requires Node.js >=16.
npm install write-prettier-fileVerified import paths — ran on the pinned version, not inferred.
Shows basic usage: import, write with default formatting, options override, and config resolution disable.
Use await writePrettierFile(...) instead of writePrettierFile.sync(...).
Use import writePrettierFile from 'write-prettier-file' (or const writePrettierFile = (await import('write-prettier-file')).default) in CommonJS via dynamic import.Use async version or upgrade to v3 with await.
Use new URL('file:///path') or pass a string path.Check prettier-format docs for supported options.
Use async version: await writePrettierFile(...) or if needed v2.x.
Use dynamic import: const writePrettierFile = (await import('write-prettier-file')).defaultRun npm install write-prettier-file, ensure package.json has it as dependency.