Node.js project with no package.json

后端 未结 3 787
面向向阳花
面向向阳花 2021-02-01 16:14

Is it ok to have a node.js project with no package.json? The ones I see on the internet all come with package.json

What is the effect of having no package.json?

3条回答
  •  既然无缘
    2021-02-01 16:50

    It is created automatically if you write npm init.

    Then, every package you add using npm install packagename --save will be added to the dependencies list.

    You need package.json so that when you want to use your project on another machine you don't have to copy all node_modules, but only your .js files you have written, assets and package.json. You can then run npm install command and it will automatically download and install all the required modules (found in the list of dependencies inside package.json).

    You can also manually create or edit it, but it's easier to add --save when installing a module so you don't have to worry about package versions and stuff like that.

    Also if you want to create a npm package, an open source project or stuff other people will use, it's either required or the norm to have this package.json file describing your project.

提交回复
热议问题