ee2 ee2 - 18 days ago 7
Node.js Question

NPM: difficulty in installing new modules

I am facing problems installing any new modules in nmp.

npm install modulename
. But when i use
-g
flag, it installs, but My script still does not recognize it. What is the problem and a possible solution?

The debug log is shown below.

devanshd:~/workspace $ cat /home/ubuntu/workspace/npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/home/ubuntu/.nvm/versions/node/v4.1.2/bin/node',
1 verbose cli '/home/ubuntu/.nvm/versions/node/v4.1.2/bin/npm',
1 verbose cli 'install',
1 verbose cli 'mocha' ]
2 info using npm@4.0.2
3 info using node@v4.1.2
4 silly loadCurrentTree Starting
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData mocha
8 silly fetchNamedPackageData mocha
9 silly mapToRegistry name mocha
10 silly mapToRegistry using default registry
11 silly mapToRegistry registry http://localhost:15443/
12 silly mapToRegistry data Result {
12 silly mapToRegistry raw: 'mocha',
12 silly mapToRegistry scope: null,
12 silly mapToRegistry escapedName: 'mocha',
12 silly mapToRegistry name: 'mocha',
12 silly mapToRegistry rawSpec: '',
12 silly mapToRegistry spec: 'latest',
12 silly mapToRegistry type: 'tag' }
13 silly mapToRegistry uri http://localhost:15443/mocha
14 verbose request uri http://localhost:15443/mocha
15 verbose request no auth needed
16 info attempt registry request try #1 at 9:55:48 AM
17 verbose request id bb344d5f4ea94faf
18 http request GET http://localhost:15443/mocha
19 http 404 http://localhost:15443/mocha
20 verbose headers { 'content-type': 'application/json',
20 verbose headers date: 'Sat, 19 Nov 2016 09:55:48 GMT',
20 verbose headers connection: 'keep-alive',
20 verbose headers 'content-length': '19' }
21 silly get cb [ 404,
21 silly get { 'content-type': 'application/json',
21 silly get date: 'Sat, 19 Nov 2016 09:55:48 GMT',
21 silly get connection: 'keep-alive',
21 silly get 'content-length': '19' } ]
22 silly fetchPackageMetaData Error: missing : mocha
22 silly fetchPackageMetaData at makeError (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:302:12)
22 silly fetchPackageMetaData at CachingRegistryClient.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:290:14)
22 silly fetchPackageMetaData at Request._callback (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:210:14)
22 silly fetchPackageMetaData at Request.self.callback (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/request/request.js:186:22)
22 silly fetchPackageMetaData at emitTwo (events.js:87:13)
22 silly fetchPackageMetaData at Request.emit (events.js:172:7)
22 silly fetchPackageMetaData at Request.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/request/request.js:1081:10)
22 silly fetchPackageMetaData at emitOne (events.js:77:13)
22 silly fetchPackageMetaData at Request.emit (events.js:169:7)
22 silly fetchPackageMetaData at IncomingMessage.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/request/request.js:1001:12)
22 silly fetchPackageMetaData error for mocha { [Error: missing : mocha] pkgid: 'mocha', statusCode: 404, code: 'E404' }
23 silly rollbackFailedOptional Starting
24 silly rollbackFailedOptional Finishing
25 silly runTopLevelLifecycles Finishing
26 silly install printInstalled
27 verbose stack Error: missing : mocha
27 verbose stack at makeError (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:302:12)
27 verbose stack at CachingRegistryClient.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:290:14)
27 verbose stack at Request._callback (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:210:14)
27 verbose stack at Request.self.callback (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/request/request.js:186:22)
27 verbose stack at emitTwo (events.js:87:13)
27 verbose stack at Request.emit (events.js:172:7)
27 verbose stack at Request.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/request/request.js:1081:10)
27 verbose stack at emitOne (events.js:77:13)
27 verbose stack at Request.emit (events.js:169:7)
27 verbose stack at IncomingMessage.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/request/request.js:1001:12)
28 verbose statusCode 404
29 verbose pkgid mocha
30 verbose cwd /home/ubuntu/workspace
31 error Linux 4.2.0-c9
32 error argv "/home/ubuntu/.nvm/versions/node/v4.1.2/bin/node" "/home/ubuntu/.nvm/versions/node/v4.1.2/bin/npm" "install" "mocha"
33 error node v4.1.2
34 error npm v4.0.2
35 error code E404
36 error 404 missing : mocha
37 error 404
38 error 404 'mocha' is not in the npm registry.
39 error 404 You should bug the author to publish it (or use the name yourself!)
40 error 404 Note that you can also install from a
41 error 404 tarball, folder, http url, or git url.
42 verbose exit [ 1, true ]

Answer

Something messed up Your default url to npm. It points at http://localhost:15443/

Use npm config set registry https://registry.npmjs.org/ to fix it