NPM-INIT(1)
π npm-init β create a package.json file π
okay bestie so this is the npm-init(1) page, from the npm manual, and it's genuinely one of the most useful little commands ever. it's giving "let me set up your whole project for you" main character energy. let's go. π
β¨ Synopsis β¨
npm init <package-spec> (same as `npx create-<package-spec>`)
npm init <@scope> (same as `npx <@scope>/create`)
aliases: create, innit
that's it. that's the whole vibe. two lines, two aliases, infinite possibilities. lowkey iconic. π
πΈ Description πΈ
so npm init <initializer> is what you use to set up a new npm package or an existing one. either way, it's got you. π«Ά
the initializer here is an npm package literally named create-<initializer>. npm installs it (via npm help npm-exec) and then runs its main bin β which is presumably creating or updating package.json and doing all the other init-adjacent operations. iykyk. π₯
the init command gets transformed into a corresponding npm exec operation like this:
npm init foo->npm exec create-foonpm init @usr/foo->npm exec @usr/create-foonpm init @usr->npm exec @usr/createnpm init @usr@2.0.0->npm exec @usr/create@2.0.0npm init @usr/foo@2.0.0->npm exec @usr/create-foo@2.0.0
look at that mapping. it's so clean. π€©
now β if you just call npm init with no initializer at all, it falls back to the legacy init behavior. it'll ask you a bunch of questions, and then write a package.json for you. it tries to make reasonable guesses based on existing fields, dependencies, and options you selected. and it is strictly additive, meaning it keeps any fields and values that were already set. no clobbering. we love a respectful queen. π
you can also use -y/--yes to skip the questionnaire entirely (no thoughts, head empty, just ship it π). and if you pass --scope, it'll create a scoped package.
note bestie: if a user already has thecreate-<initializer>package installed globally, that's the onenpm initwill use. so if you want npm to grab the latest version, or some other specific version, you must say so explicitly:
npm init foo@latest# fetches and runs the latestcreate-foofrom the registrynpm init foo@1.2.3# runscreate-foo@1.2.3specifically
π¦ Forwarding additional options π¦
any additional options get passed directly to the command, so npm init foo -- --hello maps to npm exec -- create-foo --hello. the -- is doing the lord's work fr fr. β¨
and to better illustrate how options get forwarded, here's a more evolved example showing options passed to both the npm cli and a create package β these two commands are equivalent:
npm init foo -y --registry=<url> -- --hello -anpm exec -y --registry=<url> -- create-foo --hello -a
see how they match up? gorgeous. no notes. π
π Examples π
create a new React-based project using create-react-app (npm: https://npm.im/create-react-app):
$ npm init react-app ./my-react-app
create a new esm-compatible package using create-esm (npm: https://npm.im/create-esm):
$ mkdir my-esm-lib && cd my-esm-lib
$ npm init esm --yes
generate a plain old package.json using legacy init:
$ mkdir my-npm-pkg && cd my-npm-pkg
$ git init
$ npm init
generate it without having it ask any questions (the no thoughts just vibes special):
$ npm init -y
set the private flag to true in package.json:
$ npm init --init-private -y
every single one of these is a slay. pick your fighter. π
π§ Workspaces support π§
yes bestie, you can create a new workspace inside your project using the workspace config option. when you run npm init -w <dir>, the cli creates the folders and boilerplate it expects, and adds a reference in your project package.json "workspaces": [] property so the newly generated workspace is properly set up as, y'know, a workspace. π
given a project with no workspaces, e.g:
+-- package.json
you may generate a new workspace using the legacy init:
$ npm init -w packages/a
that generates a new folder and package.json file, while also updating your top-level package.json to add the reference to this new workspace:
+-- package.json
`-- packages
`-- a
`-- package.json
the workspaces init also supports the npm init <initializer> -w <dir> syntax, following the same set of rules explained earlier in the Description section up top. similar to the previous example of creating a new React-based project using create-react-app (npm: https://npm.im/create-react-app), the following syntax makes sure to create the new react app as a nested workspace within your project and configures your package.json to recognize it as such:
npm init -w packages/my-react-app react-app .
this makes sure your react app gets generated as expected. but there's one important consideration to keep in mind: npm exec 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 by a dot to represent the current directory in that context, e.g: react-app .:
+-- package.json
`-- packages
+-- a
| `-- package.json
`-- my-react-app
+-- README
+-- package.json
`-- ...
the way that tree just grows. obsessed. π±
π Configuration π
init-author-name
- Default:
"" - Type: String
the value npm init should use by default for the package author's name.
init-author-url
- Default:
"" - Type:
""or URL
the value npm init should use by default for the package author's homepage.
init-license
- Default:
"" - Type: String
the value npm init should use by default for the package license. if not set, the license field will be omitted from new packages. (so don't come for npm when your package has no license, okay? π)
init-module
- Default:
"~/.npm-init.js" - Type: Path
a module that will be loaded by the npm init command. see the documentation for the init-package-json module (npm: https://github.com/npm/init-package-json) for more information, or npm help init.
init-type
- Default:
"commonjs" - Type: String
the value that npm init should use by default for the package.json type field.
init-version
- Default:
"1.0.0" - Type: SemVer string
the value that npm init should use by default for the package version number, if not already set in package.json.
init-private
- Default:
false - Type: Boolean
the value npm init should use by default for the package's private flag.
yes
- Default:
null - Type: null or Boolean
automatically answer "yes" to any prompts that npm might print on the command line. the yes queen of config options. π
force
- Default:
false - Type: Boolean
removes various protections against unfortunate side effects, common mistakes, unnecessary performance degradation, and malicious input. basically the "hold my iced coffee" option. π
- Allow clobbering non-npm files in global installs.
- Allow the
npm versioncommand to work on an unclean git repository. - Allow deleting the cache folder with
npm cache clean. - Allow installing packages that have an
enginesdeclaration requiring a different version of npm. - Allow installing packages that have an
enginesdeclaration requiring a different version of node, even if--engine-strictis enabled. - Allow
npm audit fixto install modules outside your stated dependency range (including SemVer-major changes). - Allow unpublishing all versions of a published package.
- Allow conflicting
peerDependenciesto be installed in the root project. - Implicitly set
--yesduringnpm init. - Allow clobbering existing values in
npm pkg - Allow unpublishing of entire packages (not just a single version).
β οΈ if you don't have a clear idea of what you want to do, it is strongly recommended that you do not use this option! like genuinely bestie. do not. π
scope
- Default: the scope of the current project, if any, or
"" - Type: String
associate an operation with a scope for a scoped registry.
useful when logging in to or out of a private registry:
# log in, linking the scope to the custom registry
npm login --scope=@mycorp --registry=https://registry.mycorp.com
# log out, removing the link and the auth token
npm logout --scope=@mycorp
this causes @mycorp to be mapped to the registry for future installation of packages specified according to the pattern @mycorp/package.
this also causes npm init to create a scoped package:
# accept all defaults, and create a package named "@foo/whatever",
# instead of just named "whatever"
npm init --scope=@foo --yes
scoped and slaying. π
workspace
- Default:
- Type: String (can be set multiple times)
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.
valid values for the workspace config are either:
- Workspace names
- Path to a workspace directory
- Path to a parent workspace directory (will result in selecting all workspaces within that folder)
when set for the npm init command, this may be set to the folder of a workspace that does not yet exist, to create the folder and set it up as a brand new workspace within the project. (yes, it'll just make it. manifesting works. β¨)
this value is not exported to the environment for child processes.
workspaces
- Default:
null - Type: null or Boolean
set to true to run the command in the context of all configured workspaces.
explicitly setting this to false will cause commands like install to ignore workspaces altogether. when not set explicitly:
- Commands that operate on the
node_modulestree (install,update, etc.) will link workspaces into thenode_modulesfolder. - Commands that do other things (
test,exec,publish, etc.) will operate on the root project, unless one or more workspaces are specified in theworkspaceconfig.
this value is not exported to the environment for child processes.
workspaces-update
- Default:
true - Type: Boolean
if set to true, the npm cli will run an update after operations that may possibly change the workspaces installed to the node_modules folder. keeping things fresh, as she should. πΈ
include-workspace-root
- Default:
false - Type: Boolean
include the workspace root when workspaces are enabled for a command.
when false, specifying individual workspaces via the workspace config, or all workspaces via the workspaces flag, will cause npm to operate only on the specified workspaces, and not on the root project. (sorry root, you're not invited to this one π«Ά)
this value is not exported to the environment for child processes.
β See Also β
npm help "package spec"init-package-jsonmodule (npm:http://npm.im/init-package-json)package.json(/configuring-npm/package-json)npm help versionnpm help scopenpm help execnpm help workspaces
okay that's the whole page!! go forth and init your little heart out bestie, you're gonna do amazing πβ¨
npm@12.2.1 Β· October 2026 Β· mwah, that's the sign-off, ily, bye ππ¦
π¦ where this page comes from
- arch rolling: npm 12.2.1-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms