logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Configuration

       <!-- AUTOGENERATED CONFIG DESCRIPTIONS -->

Description

npminit<initializer> can be used to set up a new or existing npm
       package.

       initializer in this case is an npm package named create-<initializer>,
       which will be installed by npm-exec, and then have its
       main bin executed -- presumably creating or updating package.json and
       running any other initialization-related operations.

       The init command is transformed to a corresponding npmexec operation as
       follows:

        • npminitfoo -> npmexeccreate-foonpminit@usr/foo -> npmexec@usr/create-foonpminit@usr -> npmexec@usr/createnpminit@usr@2.0.0 -> npmexec@usr/create@2.0.0npminit@usr/foo@2.0.0 -> npmexec@usr/create-foo@2.0.0

       If the initializer is omitted (by just calling npminit), 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 -y/--yes to skip the questionnaire altogether. If
       you pass --scope, it will create a scoped package.

       Note: if a user already has the create-<initializer> package
       globally installed, that will be what npminit uses.  If you want npm
       to use the latest version, or another specific version you must specify
       it:

        • npminitfoo@latest # fetches and runs the latest create-foo from
          the registry

        • npminitfoo@1.2.3 #  runs create-foo@1.2.3 specifically

   Forwardingadditionaloptions
       Any additional options will be passed directly to the command, so npminitfoo----hello will map to npmexec--create-foo--hello.

       To better illustrate how options are forwarded, here's a more evolved
       example showing options passed to both the npmcli and a create package,
       both following commands are equivalent:

        • npminitfoo-y--registry=<url>----hello-anpmexec-y--registry=<url>--create-foo--hello-a

Examples

       Create a new React-based project using
       create-react-app:
         $ npm init react-app ./my-react-app

       Create a new esm-compatible package using
       create-esm:
         $ mkdir my-esm-lib && cd my-esm-lib
         $ npm init esm --yes

       Generate a plain old package.json using legacy init:
         $ mkdir my-npm-pkg && cd my-npm-pkg
         $ git init
         $ npm init

       Generate it without having it ask any questions:
         $ npm init -y

Name

npm-init

See Also

        • package spec

        • init-package-json module

        • package.json

        • npm version

        • npm scope

        • npm exec

        • npm workspaces

9.2.0                                               May 2024                                         NPM-INIT(1)

Synopsis

       <!-- AUTOGENERATED USAGE DESCRIPTIONS -->

Workspaces Support

       It's possible to create a new workspace within your project by using the
       workspace config option. When using npminit-w<dir> the cli will
       create the folders and boilerplate expected while also adding a reference
       to your project package.json&quot;workspaces&quot;:[] property in order to make
       sure that new generated workspace is properly set up as such.

       Given a project with no workspaces, e.g:
         .
         +-- package.json

       You may generate a new workspace using the legacy init:
         $ npm init -w packages/a

       That will generate a new folder and package.json file, while also updating
       your top-level package.json to add the reference to this new workspace:
         .
         +-- package.json
         `-- packages
            `-- a
                `-- package.json

       The workspaces init also supports the npminit<initializer>-w<dir>
       syntax, following the same set of rules explained earlier in the initial
       Description section of this page. Similar to the previous example of
       creating a new React-based project using
       create-react-app, the following syntax
       will make sure to create the new react app as a nested workspace within your
       project and configure your package.json to recognize it as such:
         npm init -w packages/my-react-app react-app .

       This will make sure to generate your react app as expected, one important
       consideration to have in mind is that npmexec is going to be run in the
       context of the newly created folder for that workspace, and that's the reason
       why in this example the initializer uses the initializer name followed with a
       dot to represent the current directory in that context, e.g: react-app.:
         .
         +-- package.json
         `-- packages
            +-- a
            |   `-- package.json
            `-- my-react-app
                +-- README
                +-- package.json
                `-- ...

See Also