npm install add to package.json code example

Example 1: install npm globally

npm install npm@latest -g

Example 2: npm install dev dependencies

npm install <package-name> --save-dev

Example 3: npm install and add to dependancies

npm i packageName -save

Example 4: install node modules

// Install as a dependency
npm install --save packageName
// OR
npm install --save package1 package2
// OR
npm install --save package@version
// OR
npm i -s packageName

// Install as a dev-dependency
npm install --save-dev package@version
// OR
npm i -D packageName

//Install globally
npm install --global packageName
//OR
npm i -g packageName

// You might need SU access on macos/linux to install globally