Node.js + Socket.io + Windows 7 / 8?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7274442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.js + Socket.io + Windows 7 / 8?
提问by Hyman
I've been searching everywhere, but can't seem to find a solution. Is it possible to install Socket.io on Node.js on Windows 7?
我一直在到处寻找,但似乎无法找到解决方案。是否可以在 Windows 7 上的 Node.js 上安装 Socket.io?
If not, is there some sort of alternative, or do you know of any future Windows support?
如果没有,是否有某种替代方案,或者您是否知道未来的任何 Windows 支持?
Usually the Node.js package manager is used, however I can't find a way of installing that on Windows. http://npmjs.org/
通常使用 Node.js 包管理器,但是我找不到在 Windows 上安装它的方法。http://npmjs.org/
I'm currently using Node.exe (not running it through Cygwin).
我目前正在使用 Node.exe(不是通过 Cygwin 运行它)。
This is how I'd imagine it would be installed on Windows, if NPM worked:
如果 NPM 工作正常,这就是我想象它会安装在 Windows 上的方式:
npm install socket.io
Node Package Manager now works on Windows 7
节点包管理器现在适用于 Windows 7
Simply install Node.jsand type npm install socket.iointo the Windows console and look in C:\Users\[insert username]\node_modules.
只需安装Node.js并npm install socket.io在 Windows 控制台中键入并查看C:\Users\[insert username]\node_modules.
采纳答案by Velojet
I am confirming that npm install socket.ioworks perfectly with Node.js 0.6.10 on Windows 7 (remember to run cmdas Administrator).
我确认 npm install socket.io与 Windows 7 上的 Node.js 0.6.10 完美配合(记得以管理员身份运行cmd)。
回答by user972553
For anyone who is having trouble getting Node.js and socket.io working on Windows...
对于在 Windows 上运行 Node.js 和 socket.io 时遇到问题的任何人...
There is the nodejs-win project on Google Code.
Google Code 上有 nodejs-win 项目。
http://code.google.com/p/nodejs-win/downloads/detail?name=node_setup_0.5.6.7.exe&can=2&q=
http://code.google.com/p/nodejs-win/downloads/detail?name=node_setup_0.5.6.7.exe&can=2&q=
And here is a video that shows the basics of using it.
这是一个视频,展示了使用它的基础知识。
回答by Hyman
Now that Node.js version 0.6.0 is available, and it seems pretty stable so far, I'm going to suggest using it if you're planning on developing on Windows.
现在 Node.js 版本 0.6.0 已经可用,而且目前看起来相当稳定,如果您计划在 Windows 上进行开发,我建议您使用它。
回答by Raynos
Either use a Linux box or git clonethe socket.io repository and requireit from a local path.
使用 Linux box 或git clonesocket.io 存储库,require并从本地路径使用它。
You will have to copy the entire socket.io library into, for example, lib/socket.io/
例如,您必须将整个 socket.io 库复制到 lib/socket.io/
Then var io = require("./lib/socket.io/index.js
然后 var io = require("./lib/socket.io/index.js
回答by Layke
npm runs on Node.js. If you are having problems running npm, then you should also be having problems with Node.js. Assuming you are running Node.js through Cygwin, then you should be able to run
npm 在 Node.js 上运行。如果您在运行 npm 时遇到问题,那么您也应该在使用 Node.js 时遇到问题。假设您通过 Cygwin 运行 Node.js,那么您应该能够运行
node npm install socket.io
node npm install socket.io
(Which is the same as npm install socket.io)
(这与 npm install socket.io 相同)
Also.
还。
Npm is just the Node.js package manager. There is nothing that it provides that you can't get from the repositories themselves. It is just, for obvious reasons, a lot easier to use npm.
Npm 只是 Node.js 包管理器。它提供了您无法从存储库本身获得的任何内容。出于显而易见的原因,使用 npm 容易得多。
If you want the socket.io included, then just create a node_modules directory inside of your /libdirectory or wherever your project is, and then clone the socket.io to it.
如果您想要包含 socket.io,那么只需在您的/lib目录内或您的项目所在的任何位置创建一个 node_modules 目录,然后将 socket.io 克隆到它。
https://github.com/LearnBoost/socket.io
https://github.com/LearnBoost/socket.io
Edit
编辑
The OP indicated that he is using node.exe. There is no way currently as of 1st September 2011 to use npm with node.exe. It is currently on the node.exe roadmap and will hopefully be completed soon, but not as of today. (Check the mailing list if you want to be updated).
OP 表示他正在使用 node.exe。截至 2011 年 9 月 1 日,目前无法将 npm 与 node.exe 一起使用。它目前在 node.exe 路线图上,有望很快完成,但不会在今天完成。(如果您想更新,请检查邮件列表)。
回答by Mindw0rk
Since the 0.6.6 version (as far as I remember) Node.js has a normal version for Windows, and after installing it a npm.exe file appears in the install directory, not sure how exactly I was running it, maybe something like node npm install socket.io.
由于 0.6.6 版本(据我所知)Node.js 有一个适用于 Windows 的普通版本,安装它后,安装目录中会出现一个 npm.exe 文件,不确定我是如何运行它的,可能类似于node npm install socket.io.
Or maybe npm install socket.io. If none of these works, try to execute npm by typing full path to it (unless you have added a system variable for the path). For the record - I have successfully installed sokcet.io on Windows 7 via npm :)
或者也许npm install socket.io。如果这些都不起作用,请尝试通过键入完整路径来执行 npm(除非您为路径添加了系统变量)。作为记录 - 我已经通过 npm 在 Windows 7 上成功安装了 sokcet.io :)
回答by Olatunde Garuba
Create a file called package.jsonin your project directory with the following.
package.json使用以下内容在您的项目目录中创建一个文件。
{
"name": "project name",
"description": "project description,
"version": "0.0.1",
"dependencies": {
"express": "2.4.6",
"socket.io": "version"
}
}
Then run the npm install
然后运行 npm install
回答by PodTech.io
I had the same problem with Node.js v10.22 on Windows 7 - this worked for me:
我在 Windows 7 上使用 Node.js v10.22 遇到了同样的问题 - 这对我有用:
npm install [email protected]
回答by Ron Reiter
For me, downloading the modules directly from GitHub and putting them in the "node_modules" directory works. AFAIK that's what npm does. It works both if you put it in your user directory, or in the same directory as node.exe.
对我来说,直接从 GitHub 下载模块并将它们放在“node_modules”目录中是可行的。AFAIK 这就是 npm 所做的。如果你把它放在你的用户目录中,或者放在与 node.exe 相同的目录中,它都可以工作。
Too bad there's no Windows port for npm, since there's almost no porting needed to be done, and that node comes as a stand-alone executable instead of an installer, like Python.
太糟糕了,没有用于 npm 的 Windows 端口,因为几乎不需要进行移植,并且该节点作为独立的可执行文件而不是安装程序(如 Python)提供。

