Is it possible to automatically install the required modules for a node.js script?

后端 未结 4 1021
离开以前
离开以前 2021-01-01 20:07

Is it possible to automatically download the required modules for a node.js script? I\'m wondering if it\'s possible to generate a list of required modules for a node.js scr

4条回答
  •  一向
    一向 (楼主)
    2021-01-01 20:31

    Yes, there is a great piece of code called NPM for exactly this: https://npmjs.org/

    You specify dependent packages in a package.json file (see the docs for syntax) and you can use npm install . to pull them in all at once, and then require them from your script.

    Package.json syntax page: https://docs.npmjs.com/getting-started/using-a-package.json

    The first time you install a module, your can provide any number of modules to install, and add the --save argument to automatically add it to your package.json

    npm i --save dnode request bluebird
    

    The next time, someone will execute npm i it will automatically install all the modules specified in your package.json

提交回复
热议问题