Using npm behind Proxy Server

Posted on

Remember when I previously execute node but it accidentally display an error message as shown below :

root@hostname:/var/www/html# npm install --global gulp-cli
npm ERR! Linux 4.4.0-24-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "--global" "gulp-cli"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ECONNRESET

npm ERR! network tunneling socket could not be established, cause=write EPROTO
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'

npm ERR! Please include the following file with any support request:
npm ERR! /var/www/html/laravel-electron/npm-debug.log
root@hostname:/var/www/html#

When I try to install gulp-cli using npm suddenly the error above has risen. Based on the information given npm has a network problem related to network connectity. Since I am positively sure that I execute npm behind a network proxy I try to configure the proxy for npm to be executed properly.

Having myself searching through google and finally found this website on using npm behind a proxy  > https://jjasonclark.com/how-to-setup-node-behind-web-proxy, I try to perform the solution by typing the following command on the bash prompt :

root@hostname:~# npm config set proxy http://my-proxy-address:my-proxy-port-number
root@hostname:~# npm config set https-proxy http://my-proxy-address:my-proxy-port-number
root@hostname:~# npm install --global gulp-cli
/usr/local/bin/gulp -> /usr/local/lib/node_modules/gulp-cli/bin/gulp.js
/usr/local/lib
└─┬ gulp-cli@1.2.2                                                                                                      
  ├── archy@1.0.0                                                                                                       
  ├─┬ chalk@1.1.3                                                                                                       
  │ ├── ansi-styles@2.2.1                                                                                               
  │ ├── escape-string-regexp@1.0.5                                                                                      
  │ ├─┬ has-ansi@2.0.0                                                                                                  
  │ │ └── ansi-regex@2.0.0                                                                                              
  │ ├── strip-ansi@3.0.1                                                                                                
  │ └── supports-color@2.0.0 
  ├─┬ fancy-log@1.2.0 
  │ └── time-stamp@1.0.1 
  ├─┬ gulplog@1.0.0 
  │ └─┬ glogg@1.0.0 
  │   └── sparkles@1.0.0 
  ├── interpret@1.0.1 
  ├─┬ liftoff@2.3.0 
  │ ├── extend@3.0.0 
  │ ├─┬ findup-sync@0.4.2 
  │ │ ├─┬ detect-file@0.1.0 
  │ │ │ └── fs-exists-sync@0.1.0 
  │ │ ├── is-glob@2.0.1 
  │ │ └─┬ resolve-dir@0.1.1 
  │ │   └─┬ global-modules@0.2.3 
  │ │     ├─┬ global-prefix@0.1.4 
  │ │     │ ├── ini@1.3.4 
  │ │     │ ├─┬ osenv@0.1.3 
  │ │     │ │ └── os-tmpdir@1.0.1 
  │ │     │ └─┬ which@1.2.10 
  │ │     │   └── isexe@1.1.2 
  │ │     └── is-windows@0.2.0 
  │ ├─┬ fined@1.0.1 
  │ │ ├── expand-tilde@1.2.2 
  │ │ ├── lodash.assignwith@4.2.0 
  │ │ ├── lodash.isarray@4.0.0 
  │ │ ├── lodash.isempty@4.4.0 
  │ │ ├── lodash.pick@4.4.0 
  │ │ └─┬ parse-filepath@1.0.1 
  │ │   ├─┬ is-absolute@0.2.5 
  │ │   │ ├─┬ is-relative@0.2.1 
  │ │   │ │ └─┬ is-unc-path@0.1.1 
  │ │   │ │   └── unc-path-regex@0.1.2 
  │ │   │ └── is-windows@0.1.1 
  │ │   ├── map-cache@0.2.2 
  │ │   └─┬ path-root@0.1.1 
  │ │     └── path-root-regex@0.1.2 
  │ ├── flagged-respawn@0.3.2 
  │ ├── lodash.mapvalues@4.6.0 
  │ ├── rechoir@0.6.2 
  │ └── resolve@1.1.7 
  ├── lodash.isfunction@3.0.8 
  ├── lodash.isplainobject@4.0.6 
  ├── lodash.isstring@4.0.1 
  ├── lodash.sortby@4.7.0 
  ├─┬ matchdep@1.0.1 
  │ ├─┬ findup-sync@0.3.0 
  │ │ └─┬ glob@5.0.15 
  │ │   ├─┬ inflight@1.0.5 
  │ │   │ └── wrappy@1.0.2 
  │ │   ├── inherits@2.0.1 
  │ │   ├─┬ minimatch@3.0.3 
  │ │   │ └─┬ brace-expansion@1.1.6 
  │ │   │   ├── balanced-match@0.4.2 
  │ │   │   └── concat-map@0.0.1 
  │ │   ├── once@1.3.3 
  │ │   └── path-is-absolute@1.0.0 
  │ ├─┬ micromatch@2.3.11 
  │ │ ├─┬ arr-diff@2.0.0 
  │ │ │ └── arr-flatten@1.0.1 
  │ │ ├── array-unique@0.2.1 
  │ │ ├─┬ braces@1.8.5 
  │ │ │ ├─┬ expand-range@1.8.2 
  │ │ │ │ └─┬ fill-range@2.2.3 
  │ │ │ │   ├── is-number@2.1.0 
  │ │ │ │   ├─┬ isobject@2.1.0 
  │ │ │ │   │ └── isarray@1.0.0 
  │ │ │ │   ├── randomatic@1.1.5 
  │ │ │ │   └── repeat-string@1.5.4 
  │ │ │ ├── preserve@0.2.0 
  │ │ │ └── repeat-element@1.1.2 
  │ │ ├─┬ expand-brackets@0.1.5 
  │ │ │ └── is-posix-bracket@0.1.1 
  │ │ ├── extglob@0.3.2 
  │ │ ├── filename-regex@2.0.0 
  │ │ ├── is-extglob@1.0.0 
  │ │ ├─┬ kind-of@3.0.4 
  │ │ │ └── is-buffer@1.1.4 
  │ │ ├── normalize-path@2.0.1 
  │ │ ├─┬ object.omit@2.0.0 
  │ │ │ ├─┬ for-own@0.1.4 
  │ │ │ │ └── for-in@0.1.5 
  │ │ │ └── is-extendable@0.1.1 
  │ │ ├─┬ parse-glob@3.0.4 
  │ │ │ ├─┬ glob-base@0.3.0 
  │ │ │ │ └── glob-parent@2.0.0 
  │ │ │ └── is-dotfile@1.0.2 
  │ │ └─┬ regex-cache@0.4.3 
  │ │   ├── is-equal-shallow@0.1.3 
  │ │   └── is-primitive@2.0.0 
  │ └── stack-trace@0.0.9 
  ├── mute-stdout@1.0.0 
  ├── pretty-hrtime@1.0.2 
  ├─┬ semver-greatest-satisfied-range@1.0.0 
  │ ├── semver@4.3.6 
  │ └── semver-regex@1.0.0 
  ├─┬ tildify@1.2.0 
  │ └── os-homedir@1.0.1 
  ├─┬ v8flags@2.0.11 
  │ └── user-home@1.1.1 
  ├─┬ wreck@6.3.0 
  │ ├── boom@2.10.1 
  │ └── hoek@2.16.3 
  └─┬ yargs@3.32.0 
    ├── camelcase@2.1.1 
    ├─┬ cliui@3.2.0 
    │ └── wrap-ansi@2.0.0 
    ├── decamelize@1.2.0 
    ├─┬ os-locale@1.4.0 
    │ └─┬ lcid@1.0.0 
    │   └── invert-kv@1.0.0 
    ├─┬ string-width@1.0.2 
    │ ├─┬ code-point-at@1.0.0 
    │ │ └── number-is-nan@1.0.0 
    │ └── is-fullwidth-code-point@1.0.0 
    ├── window-size@0.1.4 
    └── y18n@3.2.1 

After configuring proxy for npm, I finally can install gulp-cli as shown in the above output. Quite long isn’t it … ?, Thanks to anyone who wrote the article in this URL : https://jjasonclark.com/how-to-setup-node-behind-web-proxy

Cheers…

Leave a Reply