• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2section: cli-commands
3title: npm-init
4description: create a package.json file
5---
6
7# npm-init(1)
8
9## create a package.json file
10
11### Synopsis
12```bash
13npm init [--force|-f|--yes|-y|--scope]
14npm init <@scope> (same as `npx <@scope>/create`)
15npm init [<@scope>/]<name> (same as `npx [<@scope>/]create-<name>`)
16```
17
18### Examples
19
20Create a new React-based project using [`create-react-app`](https://npm.im/create-react-app):
21```bash
22$ npm init react-app ./my-react-app
23```
24
25Create a new `esm`-compatible package using [`create-esm`](https://npm.im/create-esm):
26```bash
27$ mkdir my-esm-lib && cd my-esm-lib
28$ npm init esm --yes
29```
30
31Generate a plain old package.json using legacy init:
32```bash
33$ mkdir my-npm-pkg && cd my-npm-pkg
34$ git init
35$ npm init
36```
37
38Generate it without having it ask any questions:
39```bash
40$ npm init -y
41```
42
43### Description
44
45`npm init <initializer>` can be used to set up a new or existing npm package.
46
47`initializer` in this case is an npm package named `create-<initializer>`, which
48will be installed by [`npx`](https://npm.im/npx), and then have its main bin
49executed -- presumably creating or updating `package.json` and running any other
50initialization-related operations.
51
52The init command is transformed to a corresponding `npx` operation as follows:
53
54* `npm init foo` -> `npx create-foo`
55* `npm init @usr/foo` -> `npx @usr/create-foo`
56* `npm init @usr` -> `npx @usr/create`
57
58Any additional options will be passed directly to the command, so `npm init foo
59--hello` will map to `npx create-foo --hello`.
60
61If the initializer is omitted (by just calling `npm init`), init will fall back
62to legacy init behavior. It will ask you a bunch of questions, and then write a
63package.json for you. It will attempt to make reasonable guesses based on
64existing fields, dependencies, and options selected. It is strictly additive, so
65it will keep any fields and values that were already set. You can also use
66`-y`/`--yes` to skip the questionnaire altogether. If you pass `--scope`, it
67will create a scoped package.
68
69### See Also
70
71* <https://github.com/isaacs/init-package-json>
72* [package.json](/configuring-npm/package-json)
73* [npm version](/cli-commands/npm-version)
74* [npm scope](/using-npm/scope)
75