2021-03-01 11:38:43 -05:00
|
|
|
.TH "NPM\-INIT" "1" "March 2021" "" ""
|
2011-11-26 09:21:03 -08:00
|
|
|
.SH "NAME"
|
2019-11-18 21:01:39 +02:00
|
|
|
\fBnpm-init\fR \- create a package\.json file
|
2019-11-05 14:55:08 -05:00
|
|
|
.SS Synopsis
|
2014-09-24 14:41:07 -07:00
|
|
|
.P
|
|
|
|
.RS 2
|
2014-11-04 15:08:12 -08:00
|
|
|
.nf
|
2018-04-20 18:26:37 -07:00
|
|
|
npm init [\-\-force|\-f|\-\-yes|\-y|\-\-scope]
|
|
|
|
npm init <@scope> (same as `npx <@scope>/create`)
|
|
|
|
npm init [<@scope>/]<name> (same as `npx [<@scope>/]create\-<name>`)
|
|
|
|
.fi
|
|
|
|
.RE
|
2020-11-01 07:54:36 +01:00
|
|
|
.SS Description
|
|
|
|
.P
|
|
|
|
\fBnpm init <initializer>\fP can be used to set up a new or existing npm
|
|
|
|
package\.
|
|
|
|
.P
|
|
|
|
\fBinitializer\fP in this case is an npm package named \fBcreate\-<initializer>\fP,
|
|
|
|
which will be installed by \fBnpx\fP \fIhttps://npm\.im/npx\fR, and then have its
|
|
|
|
main bin executed \-\- presumably creating or updating \fBpackage\.json\fP and
|
|
|
|
running any other initialization\-related operations\.
|
|
|
|
.P
|
|
|
|
The init command is transformed to a corresponding \fBnpx\fP operation as
|
|
|
|
follows:
|
|
|
|
.RS 0
|
|
|
|
.IP \(bu 2
|
|
|
|
\fBnpm init foo\fP \-> \fBnpx create\-foo\fP
|
|
|
|
.IP \(bu 2
|
|
|
|
\fBnpm init @usr/foo\fP \-> \fBnpx @usr/create\-foo\fP
|
|
|
|
.IP \(bu 2
|
|
|
|
\fBnpm init @usr\fP \-> \fBnpx @usr/create\fP
|
|
|
|
|
|
|
|
.RE
|
|
|
|
.P
|
|
|
|
Any additional options will be passed directly to the command, so \fBnpm init
|
|
|
|
foo \-\- \-\-hello\fP will map to \fBnpx create\-foo \-\-hello\fP\|\.
|
|
|
|
.P
|
|
|
|
If the initializer is omitted (by just calling \fBnpm init\fP), init will fall
|
|
|
|
back to legacy init behavior\. It will ask you a bunch of questions, and
|
|
|
|
then write a package\.json for you\. It will attempt to make reasonable
|
|
|
|
guesses based on existing fields, dependencies, and options selected\. It is
|
|
|
|
strictly additive, so it will keep any fields and values that were already
|
|
|
|
set\. You can also use \fB\-y\fP/\fB\-\-yes\fP to skip the questionnaire altogether\. If
|
|
|
|
you pass \fB\-\-scope\fP, it will create a scoped package\.
|
2019-11-05 14:55:08 -05:00
|
|
|
.SS Examples
|
2018-04-20 18:26:37 -07:00
|
|
|
.P
|
2020-11-01 07:54:36 +01:00
|
|
|
Create a new React\-based project using
|
|
|
|
\fBcreate\-react\-app\fP \fIhttps://npm\.im/create\-react\-app\fR:
|
2018-04-20 18:26:37 -07:00
|
|
|
.P
|
|
|
|
.RS 2
|
|
|
|
.nf
|
|
|
|
$ npm init react\-app \./my\-react\-app
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.P
|
2020-11-01 07:54:36 +01:00
|
|
|
Create a new \fBesm\fP\-compatible package using
|
|
|
|
\fBcreate\-esm\fP \fIhttps://npm\.im/create\-esm\fR:
|
2018-04-20 18:26:37 -07:00
|
|
|
.P
|
|
|
|
.RS 2
|
|
|
|
.nf
|
|
|
|
$ mkdir my\-esm\-lib && cd my\-esm\-lib
|
|
|
|
$ npm init esm \-\-yes
|
2014-11-04 15:08:12 -08:00
|
|
|
.fi
|
2014-09-24 14:41:07 -07:00
|
|
|
.RE
|
|
|
|
.P
|
2018-04-20 18:26:37 -07:00
|
|
|
Generate a plain old package\.json using legacy init:
|
2011-11-26 09:21:03 -08:00
|
|
|
.P
|
2018-04-20 18:26:37 -07:00
|
|
|
.RS 2
|
|
|
|
.nf
|
|
|
|
$ mkdir my\-npm\-pkg && cd my\-npm\-pkg
|
|
|
|
$ git init
|
|
|
|
$ npm init
|
|
|
|
.fi
|
|
|
|
.RE
|
2011-11-26 09:21:03 -08:00
|
|
|
.P
|
2018-04-20 18:26:37 -07:00
|
|
|
Generate it without having it ask any questions:
|
2011-11-26 09:21:03 -08:00
|
|
|
.P
|
2018-04-20 18:26:37 -07:00
|
|
|
.RS 2
|
|
|
|
.nf
|
|
|
|
$ npm init \-y
|
|
|
|
.fi
|
|
|
|
.RE
|
2021-01-28 17:38:39 -05:00
|
|
|
.SS A note on caching
|
|
|
|
.P
|
|
|
|
The npm cli utilizes its internal package cache when using the package
|
|
|
|
name specified\. You can use the following to change how and when the
|
|
|
|
cli uses this cache\. See npm help \fBcache\fP for more on
|
|
|
|
how the cache works\.
|
|
|
|
.SS prefer\-online
|
|
|
|
.P
|
|
|
|
Forces staleness checks for packages, making the cli look for updates
|
|
|
|
immediately even if the package is already in the cache\.
|
|
|
|
.SS prefer\-offline
|
|
|
|
.P
|
|
|
|
Bypasses staleness checks for packages\. Missing data will still be
|
|
|
|
requested from the server\. To force full offline mode, use \fBoffline\fP\|\.
|
|
|
|
.SS offline
|
|
|
|
.P
|
|
|
|
Forces full offline mode\. Any packages not locally cached will result in
|
|
|
|
an error\.
|
2019-11-05 14:55:08 -05:00
|
|
|
.SS See Also
|
2014-09-24 14:41:07 -07:00
|
|
|
.RS 0
|
|
|
|
.IP \(bu 2
|
2020-11-01 07:54:36 +01:00
|
|
|
init\-package\-json module \fIhttp://npm\.im/init\-package\-json\fR
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-18 21:01:39 +02:00
|
|
|
npm help package\.json
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-18 21:01:39 +02:00
|
|
|
npm help version
|
2015-03-06 02:57:32 -06:00
|
|
|
.IP \(bu 2
|
2019-11-05 14:55:08 -05:00
|
|
|
npm help scope
|
2021-01-28 17:38:39 -05:00
|
|
|
.IP \(bu 2
|
|
|
|
npm help exec
|
2014-09-24 14:41:07 -07:00
|
|
|
|
|
|
|
.RE
|