\fBinitializer\fR in this case is an npm package named \fBcreate-<initializer>\fR, which will be installed by npm help npm-exec, and then have its main bin executed -- presumably creating or updating \fBpackage.json\fR and running any other initialization-related operations.
If the initializer is omitted (by just calling \fBnpm init\fR), init will fall back to legacy init behavior. It will ask you a bunch of questions, and then write a package.json for you. It will attempt to make reasonable guesses based on existing fields, dependencies, and options selected. It is strictly additive, so it will keep any fields and values that were already set. You can also use \fB-y\fR/\fB--yes\fR to skip the questionnaire altogether. If you pass \fB--scope\fR, it will create a scoped package.
.P
\fINote:\fR if a user already has the \fBcreate-<initializer>\fR package globally installed, that will be what \fBnpm init\fR uses. If you want npm to use the latest version, or another specific version you must specify it:
To better illustrate how options are forwarded, here's a more evolved example showing options passed to both the \fBnpm cli\fR and a create package, both following commands are equivalent:
It's possible to create a new workspace within your project by using the \fBworkspace\fR config option. When using \fBnpm init -w <dir>\fR the cli will create the folders and boilerplate expected while also adding a reference to your project \fBpackage.json\fR\fB"workspaces": \[lB]\[rB]\fR property in order to make sure that new generated \fBworkspace\fR is properly set up as such.
That will generate a new folder and \fBpackage.json\fR file, while also updating your top-level \fBpackage.json\fR to add the reference to this new workspace:
The workspaces init also supports the \fBnpm init <initializer> -w <dir>\fR syntax, following the same set of rules explained earlier in the initial \fBDescription\fR section of this page. Similar to the previous example of creating a new React-based project using \fB\fBcreate-react-app\fR\fR\fI\(lahttps://npm.im/create-react-app\(ra\fR, the following syntax will make sure to create the new react app as a nested \fBworkspace\fR within your project and configure your \fBpackage.json\fR to recognize it as such:
This will make sure to generate your react app as expected, one important consideration to have in mind is that \fBnpm exec\fR is going to be run in the context of the newly created folder for that workspace, and that's the reason why in this example the initializer uses the initializer name followed with a dot to represent the current directory in that context, e.g: \fBreact-app .\fR:
The value \fBnpm init\fR should use by default for the package author's name.
.SS"\fBinit-author-url\fR"
.RS0
.IP\(bu4
Default: ""
.IP\(bu4
Type: "" or URL
.RE0
.P
The value \fBnpm init\fR should use by default for the package author's homepage.
.SS"\fBinit-license\fR"
.RS0
.IP\(bu4
Default: "ISC"
.IP\(bu4
Type: String
.RE0
.P
The value \fBnpm init\fR should use by default for the package license.
.SS"\fBinit-module\fR"
.RS0
.IP\(bu4
Default: "~/.npm-init.js"
.IP\(bu4
Type: Path
.RE0
.P
A module that will be loaded by the \fBnpm init\fR command. See the documentation for the \fBinit-package-json\fR\fI\(lahttps://github.com/npm/init-package-json\(ra\fR module for more information, or npm help init.
Allow clobbering non-npm files in global installs.
.IP\(bu4
Allow the \fBnpm version\fR command to work on an unclean git repository.
.IP\(bu4
Allow deleting the cache folder with \fBnpm cache clean\fR.
.IP\(bu4
Allow installing packages that have an \fBengines\fR declaration requiring a different version of npm.
.IP\(bu4
Allow installing packages that have an \fBengines\fR declaration requiring a different version of \fBnode\fR, even if \fB--engine-strict\fR is enabled.
.IP\(bu4
Allow \fBnpm audit fix\fR to install modules outside your stated dependency range (including SemVer-major changes).
.IP\(bu4
Allow unpublishing all versions of a published package.
.IP\(bu4
Allow conflicting peerDependencies to be installed in the root project.
.IP\(bu4
Implicitly set \fB--yes\fR during \fBnpm init\fR.
.IP\(bu4
Allow clobbering existing values in \fBnpm pkg\fR
.IP\(bu4
Allow unpublishing of entire packages (not just a single version).
This will cause \fB@mycorp\fR to be mapped to the registry for future installation of packages specified according to the pattern \fB@mycorp/package\fR.
Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
When set for the \fBnpm init\fR command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
Commands that operate on the \fBnode_modules\fR tree (install, update, etc.) will link workspaces into the \fBnode_modules\fR folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, \fIunless\fR one or more workspaces are specified in the \fBworkspace\fR config.
When false, specifying individual workspaces via the \fBworkspace\fR config, or all workspaces via the \fBworkspaces\fR flag, will cause npm to operate only on the specified workspaces, and not on the root project.