Install Node.js, npm, and set the proxy

Node.js is a powerful JavaScript runtime. Its package ecosystem called npm, included, is very often used to install development frameworks that use JavaScript (Angular, Ionic, JHipster …)

To install Node.js :

  1. Download on the official Node.js website the latest LTS version (Long Term Support)
  2. Install it
  3. Check that the installation is correct by running node -v, which must return the version number

To install npm

  1. The npm  package manager is included with the installation of Node.js
  2. To check the npm version, run : npm -v
  3. To be sure to have the latest npm version (which changes more often than Node.js), run : npm install npm@latest -g
    latest tells to install the latest version,
    -g to install it globally. npm is then available everywhere on your machine (not just in the current folder).

Set the proxy

If you use npm on a corporate network, you will probably need to set the proxy. Otherwise, you’re done !

Method 1 : environment variables

Define two environment variables, that tell npm what is the proxy server, its port, and your credentials.

Windows Example :

HTTPS_PROXY=http://user:password@server:port
HTTP_PROXY=http://user:password@server:port

userand password generally correspond to the account you use to login to your machine.
If the password contains special characters, you may need to encode it in hexadecimal.

Method 2 : with npm configuration

The proxy can be set by running npm commands.

Windows Example :

npm config set https-proxy "http://user:password@server:port/"
npm config set proxy "http://user:password@server:port/"

In the 2d command, it is indeed proxy (and not http-proxy).

The values are then stored in the user-home-folder\.npmrc file.

Leave a Comment