Skip to content
jshacks.dev
Packages

Initialize a package with npm init

Initialize a package.json with npm init, skip the questions with the yes flag, and set your own defaults for author and license in npm config.

1 min read
Summarize in AI

npm init creates a package.json. It asks questions by default, and the -y flag answers them all with defaults.

Shell
mkdir acme-tool && cd acme-tool
npm init -y
Text
Wrote to /home/dev/acme-tool/package.json:

{
  "name": "acme-tool",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

The name comes from the folder, so it must be lowercase and URL-safe. To avoid editing the same fields every time, set defaults once, and later runs fill them in.

Shell
npm config set init-author-name "Your Name"
npm config set init-license "MIT"

The main field points at index.js, which may not exist. For a package using ES modules, add "type": "module" yourself, because npm init does not. See [the npm init docs](https://docs.npmjs.com/cli/v10/commands/npm-init).

npm init vite is a different form: with a name after it, npm runs the matching create- package instead.

Taggednpm
Share

More snippets

Packages

Generate a changelog from commits

Turn conventional commit messages into a CHANGELOG.md section with conventional-changelog, grouped by feature and fix. Works with any Git history.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.