2

I was wondering if it is possible to do a single installation of node packages that can then be accessed by different development applications. For example, whenever I'm working on a react app, I do npm install to get all node packages the app needs. However, it seems that this gets a lot of unneeded extras. Is there a way

  1. to just get what my app needs as specified in the package file or
  2. get everything into the node modules folder in the installation folder and access the packages from there without having to reinstall them locally in every app folder.

I'm adding the following since my question is not being answered: Let's say I have the following package.json. If I navigate to my app folder where this package.json file is located and I do npm install, what gets installed and where? My assumption is that only the packages listed in devDependencies and in dependencies will be installed and that it will be installed locally since I did not specify global. So why do I see hundreds of other packages (packages not in the list below) when I go into my node_modules folder in my app?

what I would like is to install only the packages listed below and to make them global so that if I go into another app directory I do not have to reinstall these.

{
  "devDependencies": {
    "babel-eslint": "7.1.1",
    "babel-jest": "18.0.0",
    "concurrently": "3.1.0",
    "enzyme": "2.7.1",
    "eslint": "3.12.1",
    "eslint-config-defaults": "9.0.0",
    "eslint-plugin-react": "6.7.1",
    "jest": "18.1.0",
    "json-server": "0.9.4",
    "react-addons-test-utils": "15.4.2",
    "react-test-renderer": "15.4.2",
    "rimraf": "2.5.4",
    "sass-lint": "1.10.2",
    "tslint": "4.3.1",
    "webpack-dev-server": "2.6.1"
  },
  "dependencies": {
    "bootstrap": "4.0.0-alpha.6",
    "bootstrap-loader": "2.0.0-beta.20",
    "copy-webpack-plugin": "4.0.1",
    "css-loader": "0.26.1",
    "empty": "0.10.1",
    "extract-text-webpack-plugin": "2.0.0-rc.3",
    "file-loader": "0.10.0",
    "html-loader": "0.4.3",
    "html-webpack-plugin": "2.26.0",
    "key-mirror": "1.0.1",
    "lodash": "4.16.2",
    "node-sass": "4.5.0",
    "null-loader": "0.1.1",
    "postcss": "5.2.9",
    "postcss-import": "9.1.0",
    "postcss-loader": "1.2.1",
    "raw-loader": "0.5.1",
    "react": "15.4.2",
    "react-addons-css-transition-group": "15.4.2",
    "react-dom": "15.4.2",
    "react-redux": "5.0.2",
    "react-router": "3.0.0",
    "react-router-redux": "4.0.7",
    "redux": "3.6.0",
    "redux-thunk": "2.1.0",
    "resolve-url-loader": "1.6.1",
    "sass-loader": "5.0.1",
    "style-loader": "0.13.1",
    "ts-loader": "1.3.3",
    "typescript": "2.1.4",
    "url-loader": "0.5.7",
    "webpack": "2.2.1",
    "whatwg-fetch": "2.0.3"
  },
 }
mo_maat
  • 2,110
  • 12
  • 44
  • 72

2 Answers2

1

This is exactly what global packages are for. npm i -g <package> also i recommend using nvm to manage your different node versions. This way you can have different global packages depending on version. You can even set aliases for multiple installs.

rimraf
  • 3,925
  • 3
  • 25
  • 55
  • Ok. so I'm setting up a new pc and i've copied over my react apps. I've installed nodejs. I go into my app folder and I do npm install. Is that by default going to do a global install? It is taking a very long time and my assumption was that it would only install the packages specified in my dependencies and dev dependencies in my package.json file and whatever dependencies they have and nothing else. Is my assumption wrong? – mo_maat Aug 05 '17 at 20:14
  • no you need to add the -g flag for global installs. – rimraf Aug 05 '17 at 20:22
  • you'll also have to look at your specific apps' package.jsons to see what packages you'd like to install globally. – rimraf Aug 05 '17 at 20:24
0

You can globally install nodeJs and then do npm install for the packages you need and save it in package.json. This way you would know which packages to install next time and just do npm install.