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.
npm init creates a package.json. It asks questions by default, and the -y flag answers them all with defaults.
mkdir acme-tool && cd acme-tool
npm init -yWrote 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.
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.