workspace
npm init
Creates a new package.json interactively, or when given an initializer (e.g. `npm init vite@latest`) delegates to `npm exec create-<initializer>`. `-y` accepts all defaults.
npm init [<initializer>] | npm init -y Common flags
| Flag | Purpose |
|---|---|
| --yes (-y) | Skip prompts and generate a default package.json |
| --scope <@scope> | Create a scoped package |
| --workspace <path> (-w) | Create a new workspace under the given path |
| -w <path> -y | Common combo to scaffold a workspace non-interactively |
Examples
npm init -y Create a default package.json with no prompts
npm init vite@latest my-app Delegate to create-vite for scaffolding
npm init -w packages/utils -y Create a new workspace at packages/utils
Gotcha
`npm init
Related commands
npm workspaces
A set of flags — not a standalone command — that let npm operate against one, several, or every workspace declared in the root package.json's `workspaces` array. Introduced in npm 7 and refined through npm 10.
npm exec (npx)
Runs a package's binary from a local install, the cache, or on-the-fly from the registry without a global install. `npx` is the shell-friendly shim; both are equivalent in npm 10+.
npm install
Installs a package (and its dependencies), adding it to package.json and refreshing package-lock.json. Without arguments, installs everything already declared in the current project's package.json.