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

后端 未结 10 929
梦毁少年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:59

    Command line:

    npm init
    

    will create package.json file

    To install , update and uninstall packages under dependencies into package.json file:

    Command line :

    npm install @* --save 
    

    will automatically add the latest version for the package under dependencies into package.json file

    EX:

    npm install node-markdown@* --save
    

    Command line:

    npm install  --save
    

    also will automatically add the latest version for the package under dependencies into package.json file

    if you need specific version for a package use this Command line:

    npm install @ --save
    

    will automatically add specific version of package under dependencies into package.json file

    EX:

    npm install koa-views@1.0.0 --save
    

    if you need specific range of version for a package use this Command line:

    npm install @
    

    will automatically add the latest version for the package between range of version under dependencies into package.json file

    EX:

    npm install koa-views@">1.0.0 <1.2.0" --save
    

    For more details about how to write version for package npm Doc

    Command line:

    npm update --save
    

    will update packages into package.json file and will automatically add updated version for all packages under dependencies into package.json file

    Command line:

    npm uninstall  --save
    

    will automatically remove package from dependencies into package.json file and remove package from node_module folder

提交回复
热议问题