Why are npm install && npm install <pack-name> both required?

113 views Asked by At

Why do we need both npm install and npm install base1 in the prestart section?

If npm install itself retrieves base1 from Git then why do we need to mention npm install base1 in prestart?

For one Node.js program I saw the package.json shown here:

{
  "name": "user01",
  "version": "1.5.1",
  "description": "",
  "author": "",
  "private": "true",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
    "prestart": "npm install && npm install base1 && npm install base2"
  },
  "dependencies": {
    "ain2": "*",
    "body-parser": "^1.15.0",
    "express": "^4.13.3",
    "uuid": "*",
    "request": "^2.69.0",
    "traverse": "*",
    "base1": "git+ssh://xxxxxxxxxxx/base1.git",
    "base2": "git+ssh://xxxxxxxxxx/base2.git"
  }
}
2

There are 2 answers

2
Matt On

The extra commands might do nothing in npm@3 or recent versions of npm@2 where the git remote is fetched every time. They could be a workaround for some previous git issues where code doesn't update to the latest commit on npm install (back in v0.12 releases). Specifying the package could force the fetch of the latest version of the code from git, which a plain npm install wouldn't do when the package was already installed.

To confirm what currently happens, see what the differences are for the git base1 package.

rm -rf node_modules/base1
npm install -d

rm -rf node_modules/base1    
npm install -d base1

rm -rf node_modules/base1
npm install -d
npm install -d base1

When the code in git has been updated run the two installs in debug without removing the modules

npm install -d
npm install -d base1

The extra installs are probably not required any more, if this was their purpose.

2
Blake Connally On

The first run is to get the packages, the second is to basically initialize them.

npm install

npm install (in package directory, no arguments):

Install the dependencies in the local node_modules folder.

npm install package

npm install <folder>:

Install a package that is sitting in a folder on the filesystem.

Source: NPMJS