Hylle
Hylle

Reputation: 1136

Is npm init needed?

I always thought that you should initialize npm first before installing any packages

npm init --yes

However I found out that I could just go straight to installing packages

npm i example-package

Then the package would be installed and package.json would be created at the same time.

Is there any reason I should be doing npm init first? Is it only required if I want to specify project details?

Upvotes: 15

Views: 11589

Answers (3)

Kevin James Stevens
Kevin James Stevens

Reputation: 1

Well, kind of a late answer, but as far as I know (correct me if im wrong), one of the features is it gets set up with package.json which includes the dependencies list. That way, NPM can simply install the packages on the list (via the "npm init" if you have a situation that you want to clone the app into another machine), rather than copy pasting the whole project folder.

This isn't a direct answer to the question, but, if sheds some light at some point, why not.

Upvotes: -2

Sami Kuhmonen
Sami Kuhmonen

Reputation: 31193

It is not required. You can install packages without, and everything will work.

npm init can do basically two things:

  • ask for basic project info to include in packages.json
  • create a specific type of project (for example React) by using npm init typeofproject

If you just want to use packages and don’t care about naming the project or using a template, just install packages.

Upvotes: 19

bhuvnesh pattnaik
bhuvnesh pattnaik

Reputation: 1463

npm init is there when you are installing the project very first time.

else you don't need to use npm init for installing any package

Upvotes: -1

Related Questions