npm init Explained

What npm init does, with an example.

Published November 11, 2026

npm init creates a package.json for a new project by asking questions; npm init -y accepts all defaults. npm init <initializer> also scaffolds projects, e.g. npm init vite.

How it works

package.json describes the project: name, version, scripts, dependencies and entry points.

Set defaults globally with npm config set init-author-name.

Try it

npm init -y
Wrote to /my-app/package.json
npm init vite@latest my-app

Practical examples

Quick start

npm init -y

Scaffold with a template

npm init vite@latest my-app
npm create next-app@latest

Resulting file

{ "name": "my-app", "version": "1.0.0", "scripts": {} }

ES modules

{ "type": "module" }

Common mistakes

  • Names with capitals or spaces (invalid).
  • Forgetting to set type for ESM.
  • Initialising inside a subfolder by mistake.

Key takeaways

  • npm init creates a package.json for a new project by asking questions; npm init -y accepts all defaults.
  • Run npm help <command> for every option.
  • Commit package-lock.json.

FAQ

npm init vs npm create?

They are aliases for scaffolding with initializer packages.

Does this work with yarn or pnpm?

They have equivalents with similar commands.

More JavaScript articles