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

后端 未结 10 896
梦毁少年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 <pkg>@* --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 <pkg> --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 <pkg>@<version> --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 <pkg>@<version range>
    

    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 <pkg> --save
    

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

    0 讨论(0)
  • 2020-11-29 15:01

    You can now use Yeoman - Modern Web App Scaffolding Tool on node terminal using 3 easy steps.

    First, you'll need to install yo and other required tools:

    $ npm install -g yo bower grunt-cli gulp
    

    To scaffold a web application, install the generator-webapp generator:

    $ npm install -g generator-webapp  // create scaffolding 
    

    Run yo and... you are all done:

    $ yo webapp  // create scaffolding 
    

    Yeoman can write boilerplate code for your entire web application or Controllers and Models. It can fire up a live-preview web server for edits and compile; not just that you can also run your unit tests, minimize and concatenate your code, optimize images, and more...

    Yeoman (yo) - scaffolding tool that offers an ecosystem of framework-specific scaffolds, called generators, that can be used to perform some of the tedious tasks mentioned earlier.

    Grunt / gulp - used to build, preview, and test your project.

    Bower - is used for dependency management, so that you no longer have to manually download your front-end libraries.

    0 讨论(0)
  • 2020-11-29 15:01

    Based on Pylinux's answer, below is a solution for Windows OS,

    dir node_modules > abc.txt
    FOR /F %k in (abc.txt) DO npm install --save
    

    Hope it helps.

    0 讨论(0)
  • 2020-11-29 15:03

    First off, run

    npm init
    

    ...will ask you a few questions (read this first) about your project/package and then generate a package.json file for you.

    Then, once you have a package.json file, use

    npm install <pkg> --save
    

    or

    npm install <pkg> --save-dev
    

    ...to install a dependency and automatically append it to your package.json's dependencies list.

    (Note: You may need to manually tweak the version ranges for your dependencies.)

    0 讨论(0)
提交回复
热议问题