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
- Go to the project folder
bash
cd my-project- Run the initialization
bash
npm initThis 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 -yThe 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 readyPremium
A concise answer to help you respond confidently on this topic during an interview.