Node.js、NPM、代理和 node_modules [英] Node.js, NPM, proxy and node_modules

查看:30
本文介绍了Node.js、NPM、代理和 node_modules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装节点包,但我的网络不允许我连接.我得到了标准,

I am trying to install node packages but my network won't let me connect. I get the standard,

npm ERR! network getaddrinfo ENOTFOUND

我知道这是因为我在公司网络上.但是,我对代理不是很熟悉,据我所知,我无法访问代理我不确定如何使用 NPM 取得进展.任何有关此的有用和相关的想法都受到热烈欢迎!

I understand that this is because I am on a corporate network. However, I'm not very familiar with proxies and as far as I am aware, I don't have access to one so I'm not sure how I can progress with NPM. Any helpful and related thoughts about this are warmly received!

作为一种解决方法,使用我的另一台机器,我通过电子邮件将我需要的节点模块通过电子邮件发送给自己.这些节点模块是使用 NPM 安装的,而不是在公司网络上.

As a work around, using my other machine, I have emailed myself with the node modules I require. These node modules were installed using NPM while not on the corporate network.

然而,尽管我已经将模块放在 node_modules/和我的 test_server.js 文件中,我仍然收到,

However, despite the fact that I have put the modules in node_modules/ alongside my test_server.js file, I still receive,

C:UsersJT15900Documents
odeServer>node test_server.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'knex' ... etc.

说得非常清楚,test_server.js 与 node_modules/位于同一目录中.在 node_modules/里面,我放了各种模块文件夹,比如express"和knex"等

To be really clear, test_server.js sits alongside node_modules/ in the same directory. Inside node_modules/ I have put the various module folders like 'express' and 'knex', etc.

为什么我的节点脚本无法找到这些模块以及如何更正?

Why is my node script unable to find these modules and how to I correct it?

编辑

我在超级用户处使用了一个帖子帮助发现我的代理设置.然后,我按照其他地方的概述和解决方案中的说明配置了 Node NPM 代理设置.

I used a post over at superuser to help discover my proxy settings. I then configured Node NPM proxy settings as outlined elsewhere and presented in the solution.

推荐答案

这对我有帮助 http://jjasonclark.com/how-to-setup-node-behind-web-proxy

如果公司网络有代理,你可以使用这些命令在 npm 中设置它

if the corporate network has a proxy you can set it in npm using these commands

npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

抱歉,如果您已经尝试过或者它不起作用.

Apologies if you already tried that or it doesn't work.

这篇关于Node.js、NPM、代理和 node_modules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆