Iverson
Iverson

Reputation: 179

Include package json dependencies for npm install global

I only know npm install locally particular plugin into the dependencies object in the package.json. Been doing npm install -g on many packages manually, but how do I include it inside the package.json?

eg. my current package:

  {
    "name": "mypackage",
    "version": "0.0.1",
    "private": true,
    "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "lodash": "^4.17.15",
    "react": "16.8.3",
  }
}

To include my global install modules into mypackage

├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Upvotes: 0

Views: 1563

Answers (4)

Iverson
Iverson

Reputation: 179

Appreciate with the guidance guys, just updated my question. So to add my global modules into mypackage gonna be like as per below?

{
  "name": "mypackage",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "lodash": "^4.17.15",
    "react": "16.8.3",
    "expo-cli": "3.0.8",
    "npm": "6.9.0",
    "npm-check-updates": "3.1.20",
    "react-devtools": "4.1.0",
    "react-native-cli": "2.0.1",
    "typescript": "3.6.3"
  }
}

Upvotes: 0

ArUn
ArUn

Reputation: 1337

The package will be added to your package.json when you install it from the project directory without -g

npm install --save package

you can also save the developer dependencies by

npm install --save-dev package

when you want to download a package for developers, such as grunt, gulp, then use this option

when you are distributing your code to production, these dependencies will not be available.

If you want to include packages like angular-cli you can install it as normal package and access it by referring the path inside the node_modules. like node_modules/.bin/ng build --prod

Upvotes: 0

Shams Nahid
Shams Nahid

Reputation: 6559

Go to your project root directory and execute,

npm install your-package-name

Or you can put the package-name manually in your package.json file and run,

npm install

But your package is already globally installed on your machine.

When you install an npm package, globally, using npm install -g my-package, then the package is globally available in your machine. You can use it anywhere in your machine.

But without global flag -g when you install a package, it only available inside the project scope.

So when a package is available globally, you do not need to install it in your project scope. It's a code redundant.

Upvotes: 1

Luis Avila
Luis Avila

Reputation: 37

just type

$ npm install name-of-the-dependency

This is going to install the dependency in the package.json

Upvotes: 0

Related Questions