LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

npm-init

creates a new package

TLDR

Initialize new project
$ npm init
copy
Initialize with defaults
$ npm init -y
copy
Create with initializer
$ npm init [initializer]
copy
Create React app
$ npm init react-app [my-app]
copy
Create Vite project
$ npm init vite@latest [my-app]
copy
Set default author
$ npm config set init-author-name "[name]"
copy

SYNOPSIS

npm init [options] [initializer]

DESCRIPTION

npm init creates a new package.json file. Without an initializer, it prompts for package details. With an initializer, it runs that package's setup process.Initializers like "react-app" are shorthand for "create-react-app".

PARAMETERS

-y, --yes

Accept all defaults.
--scope scope
Create scoped package.
-w, --workspace
Create workspace.
initializer
Package to run (create-*).

Interactive

npm init

Answer prompts...

With defaults

npm init -y

Using initializer (runs create-react-app)

npm init react-app my-app

Scoped package

npm init --scope=@myorg

$
# PACKAGE.JSON TEMPLATE
copy
{"name": "my-package","version": "1.0.0","description": "","main": "index.js","scripts": { "test": "echo \"Error: no test\" && exit 1" },"keywords": [],"author": "","license": "ISC"}
$
# CAVEATS

-y uses defaults which may need editing. Initializers download packages. Workspace mode for monorepos.

# SEE ALSO

npm(1), npm-install(1), npm-config(1)
copy

Copied to clipboard
Kai