Is there a way to automatically build the package.json file for Node.js projects

后端 未结 10 904
梦毁少年i
梦毁少年i 2020-11-29 14:30

Is package.json supposed to be manually edited? Couldn\'t a program like npm just look through the files, see the \"require\" statements, and then use that to put the necess

10条回答
  •  一生所求
    2020-11-29 14:58

    npm init

    to create the package.json file and then you use

    ls node_modules/ | xargs npm install --save

    to fill in the modules you have in the node_modules folder.

    Edit: @paldepind pointed out that the second command is redundant because npm init now automatically adds what you have in your node_modules/ folder. I don't know if this has always been the case, but now at least, it works without the second command.

提交回复
热议问题