本文介绍了找不到模块`express` | socket.io [node.js]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我去了Git Bash并输入 npm install socket.io 我在我的用户文件夹中找到了该目录: C:\ Users \ weka \\\
ode_modules
...无论如何,我将 socket.io 文件夹拖到我的项目 www 文件夹,因为我使用 WAMP 服务器。

So I went to Git Bash and typed npm install socket.io I found the the directory in my user folder: C:\Users\weka\node_modules... anyway, I dragged the socket.io folder into my project www folder because I am using WAMP server.

所以,这是我的 server.js 用于测试:

So, here's my server.js for testing:

var app = require('express').createServer();
var io = require('socket.io').listen(app);

io.sockets.on('connection', function (socket) {
console.log('Someone connected!');
socket.on('set nickname' , function (nickname) {
socket.nickname = nickname;
console.log(nickname + ' just connected!');
});

});

app.listen(8080);

我进入 cmd 并输入节点C:\ wamp \\\\gameTest \ server.js

我得到的错误是它找不到名为 express 模块。我以为我下载了 socket.io ?当谈到GitHub时,我是个新手......所以我可能做错了。 :\

and I get the error that it cannot find the module called express. I thought I downloaded socket.io? I am a newb when it comes to GitHub.. so I probably did it wrong. :\

帮助?

更新:我发现我没有安装它。好的,我输入 npm install express 我现在在 node_modules express 文件夹/ code>文件夹。

UPDATE: I found out I hadn't installed it. OK, I typed npm install express and I now I have express folder in my node_modules folder.

推荐答案

express socket.io 是不同的库。只需 npm install express 从您应用的根目录开始。

express and socket.io are different libraries. Just npm install express from the root of your app.

此外,请确保您的 node 依赖项位于名为 node_modules 的文件夹中 - 这是用于模块解析的约定。所以,你应该有一个看起来像这样的文件结构:

Also, make sure that your node dependencies are in a folder called node_modules - that's the convention used for module resolution. So, you should have a file structure that looks something like:

/some-app
    /node_modules
        /express
        /socket.io
    server.js

这篇关于找不到模块`express` | socket.io [node.js]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:10