Skip to main content

How do you initialize a project with npm?

You can initialize a project with npm using the npm init command, which creates a package.json file and sets the project's basic settings.


Steps and commands

  1. Go to the project folder
bash
cd my-project
  1. Run the initialization
bash
npm init

This command asks a set of questions (name, version, author, license, and so on) and creates package.json. 3. The simplified variant (no questions)

bash
npm init -y

The package.json file is created right away with default values.


The end result

After initialization, a package.json file appears in the folder, where npm stores:

  • the list of dependencies
  • versions
  • scripts (npm run ...)
  • project metadata

Summary: to initialize a project, it's enough to run npm init (or npm init -y) inside the target directory, after which you can install dependencies and add scripts.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.