Search code examples
reactjsjsonnode-modulesnpm-install

How to add node_modules as dependencies to package.json?


I want to add these 3 installations to my package.json dependencies:

  1. npm i --save @fortawesome/fontawesome-svg-core

  2. npm install --save @fortawesome/free-solid-svg-icons

  3. npm install --save @fortawesome/react-fontawesome

I already tried

npm install <@fortawesome/fontawesome-svg-core> [--save-prod]

which didn´t work.

How do I add this, so that a random person only has to type in "npm install" in order to get all the required modules?


Solution

  • To add those three packages as dependencies in your package.json file, you can use the --save or -S flag with npm install. The --save flag is the default behaviour of npm when you install packages, so you don't need to specify it explicitly.

    Here's how you can add those packages to your package.json:

    npm install @fortawesome/fontawesome-svg-core
    npm install @fortawesome/free-solid-svg-icons
    npm install @fortawesome/react-fontawesome
    

    Or you can install all of them in a single command like this:

    npm install @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons @fortawesome/react-fontawesome
    

    Once you've added these packages to your package.json file, anyone who clones your repository or downloads your project can simply run npm install to install all the required modules, including these dependencies.