npm init
Packages and runtimes
Usage
npm init [-y] | npm init <initializer>Creates a package.json; npm init <name> is a different thing altogether, downloading and running create-<name> the way npx does.
Common flags
| Flag | Meaning |
|---|---|
| -y | accept every default and write package.json at once |
| <initializer> | download and run create-<initializer> instead |
| --scope=@me | create a scoped package name |
| -w <dir> | create a workspace package under that directory |
Examples
npm init -ywrites a package.json with defaults, no questions
npm init vite@latest my-appruns create-vite; nothing like plain npm init
npm init --scope=@me -ynames the package @me/whatever
The question is always what goes where: inside this project, or on the whole machine.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does npm init do?
Creates a package.json; npm init <name> is a different thing altogether, downloading and running create-<name> the way npx does.
Q. How do I type it?
npm init [-y] | npm init <initializer> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
4 are listed here; the full set is in man npm. This command sits under Packages and runtimes.
Related commands
man page: man npm-init