init-package-json is a Node.js module designed to programmatically and interactively create or update `package.json` files, primarily used by the npm CLI itself. It provides a wizard-like experience for users, prompting for essential package metadata such as name, version, description, entry point, test command, git repository, keywords, author, and license. The current stable version is 8.2.5, with frequent maintenance releases addressing bug fixes and dependency updates, often tied to releases of other `@npmcli` packages. Its key differentiator is its integration with `promzard` for flexible, scriptable prompting and the ability to utilize custom initialization files, offering a powerful way to standardize `package.json` creation across projects or teams. It is a low-level utility most often consumed by package managers rather than directly by end-user applications.
npm install init-package-jsonVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically use `init-package-json` to create a `package.json` file in a specified directory, utilizing a custom `promzard` init file to pre-fill common fields and interact with passed configuration data.
Ensure your Node.js environment meets the specified version requirements. Update Node.js to a compatible version if necessary.
Be aware of the new `type` prompt if using interactive mode. If you rely on a specific field order, be prepared for changes in generated `package.json` files.
If providing a custom `initFile`, ensure it's a valid `promzard` script that exports a function with the expected signature `(data, cb) => {}` and utilizes the `this.config` and `this.package` context for data manipulation.Use `const init = require('init-package-json')` for CommonJS projects. If in an ESM module, consider `await import('init-package-json')` if the package provides a compatible export, or wrap it in a CommonJS context.Upgrade your Node.js environment to a version compatible with `^20.17.0` or `>=22.9.0`.
Double-check the `initFile` path to ensure it is absolute and points to an existing JavaScript file that exports a `promzard` function.