Skip to content
Latchkey

npm init: Usage, Options & Common Errors

Create a package.json or run a project initializer.

npm init creates a package.json interactively, or, given an initializer name, runs the matching create-* package - the same machinery behind npm create.

What it does

With no argument, prompts for fields and writes package.json (use -y to accept defaults non-interactively). With an initializer like npm init vite, it downloads and runs create-vite via the npm exec machinery.

Common usage

Terminal
npm init -y                 # write package.json with defaults
npm init                    # interactive prompts
npm init vite@latest        # run create-vite
npm init @scope/tool        # run @scope/create-tool

Common CI error: init hangs on prompts

A scripted npm init blocks waiting for interactive input and the job times out. Always pass -y (or --yes) in non-interactive environments so it accepts defaults instead of prompting.

.github/workflows/ci.yml
npm init -y

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →