{"id":924,"date":"2012-12-31T16:11:57","date_gmt":"2012-12-31T15:11:57","guid":{"rendered":"https:\/\/www.unicoda.com\/?p=924"},"modified":"2012-12-31T16:11:57","modified_gmt":"2012-12-31T15:11:57","slug":"npm-noproxy-configuration","status":"publish","type":"post","link":"https:\/\/www.unicoda.com\/?p=924","title":{"rendered":"NPM: noproxy Configuration"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"color: #333333; font-style: normal; line-height: 24px;\" title=\"npm\" src=\"https:\/\/npmjs.org\/static\/npm.png\" alt=\"\" width=\"518\" height=\"202\" \/><\/p>\n<p>For security reasons, every firms are generally using a proxy to manage their internet connection. Coding behind a proxy is fine. Most softwares are able to deal with it. You just have to set it in the environment variable of your GNU\/Linux OS or directly in the software.<\/p>\n<p>But there is one problem. Because every request must go through the proxy, it&rsquo;s impossible to request url based in the internal network. There is only one solution: disable proxy, make request, enable proxy. If you are using npm until now, that&rsquo;s what you have to do.<\/p>\n<p>In order to make this process easier, I&rsquo;ve made a pull request which add a noproxy configuration. When <a href=\"https:\/\/npmjs.org\/\">npm<\/a> fetches a package from a given url, the hostname is compared with noproxy configuration. If there is a match, the request is made without proxy, if not proxy is used.<\/p>\n<p>The noproxy configuration looks for a variable named \u00ab\u00a0noproxy\u00a0\u00bb in npm configuration.<br \/>\n\u00ab\u00a0noproxy\u00a0\u00bb is a string containing hostnames. So, this list of hostnames will not ever go through a proxy.<br \/>\nCode concerned:<\/p>\n<pre>var proxy = null\r\nif(npm.config.get(\"noproxy\").search(remote.hostname) === -1) {\r\n\u00a0 if (remote.protocol !== \"https:\" || \r\n      !(proxy = npm.config.get(\"https-proxy\"))) {\r\n\u00a0\u00a0\u00a0 proxy = npm.config.get(\"proxy\")\r\n\u00a0 }\r\n}\r\n\r\nvar opts = { url: remote\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 , proxy: proxy\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 , strictSSL: npm.config.get(\"strict-ssl\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 , ca: remote.host === regHost ? \r\n                                npm.config.get(\"ca\") : undefined\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 , headers: { \"user-agent\": npm.config.get(\"user-agent\") }}\r\n\r\nvar req = request(opts)<\/pre>\n<p>At the moment, I&rsquo;m still waiting for Isaacs to add the pull request in <a href=\"https:\/\/github.com\/isaacs\/npm\">npm<\/a>.<br \/>\nI hope it will be added soon.<\/p>\n<p><strong>Update:<\/strong> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Isaacs has pointed out that it&rsquo;s good for the npm bit but some modifications are still needed in\u00a0<a href=\"https:\/\/github.com\/isaacs\/npm-registry-client\">npm-registry-client<\/a>\u00a0and\u00a0<a href=\"https:\/\/github.com\/isaacs\/npmconf\">npmconf<\/a>\u00a0. So here are new additions:<\/p>\n<ul>\n<li>npmconf:<\/li>\n<\/ul>\n<pre>\u00a0,\u00a0\"noproxy\"\u00a0:\u00a0process.env.NO_PROXY\u00a0||\u00a0process.env.no_proxy\u00a0||\u00a0 \"null\"<\/pre>\n<pre>\u00a0,\u00a0\"no-proxy\"\u00a0:\u00a0[\"null\",\u00a0String]<\/pre>\n<ul>\n<li>npm-registry-client:<\/li>\n<\/ul>\n<pre>  var p = this.conf.get('proxy')\r\n  var sp = this.conf.get('https-proxy') || p\r\n  var np = this.conf.get('noproxy')\r\n\r\n  if(np.search(remote.hostname) === -1) {\r\n    opts.proxy = remote.protocol === \"https:\" ? sp : p\r\n  }<\/pre>\n<p>I hope everything is now in order so that noproxy configuration can be added to npm :).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For security reasons, every firms are generally using a proxy to manage their internet connection. Coding behind a proxy is fine. Most softwares are able to deal with it. You just have to set it in the environment variable of your GNU\/Linux OS or directly in the software. But there is one problem. Because every &hellip; <a href=\"https:\/\/www.unicoda.com\/?p=924\" class=\"more-link\">Continuer la lecture<span class=\"screen-reader-text\"> de &laquo;&nbsp;NPM: noproxy Configuration&nbsp;&raquo;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[27,81,65,34],"class_list":["post-924","post","type-post","status-publish","format-standard","hentry","category-code","tag-nodejs","tag-noproxy","tag-npm","tag-pull-request"],"_links":{"self":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/924","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=924"}],"version-history":[{"count":9,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/924\/revisions"}],"predecessor-version":[{"id":998,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/924\/revisions\/998"}],"wp:attachment":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}