Cannot find module `express` | socket.io [node.js]

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

So here is 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); 

and I enter cmd and type node C:\wamp\www\gameTest\server.js

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

reference

UPDATE: I found out that I did not install it. OK, I typed npm install express , and now I have the express folder in my node_modules folder.

+4
source share
3 answers

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

Also, make sure your node dependencies are in a folder named node_modules - this is the convention used to resolve the module. So, you should have a file structure that looks something like this:

 /some-app /node_modules /express /socket.io server.js 
+11
source

The fix for me was to run npm at the root of your project. It sets the files in relation to your project, namely how node.js then searches for them to resolve the file name.

0
source

In your case, you should copy the express module folders from C:\Users\weka\node_modules to the project directory: C:\wamp\www\gameTest\node_modules . If the project folder does not have a folder named 'node_modules' , first create it and paste these files into this folder. This method worked for me on my windows pc . Reboot the node server and run the node C:\wamp\www\gameTest\server.js . Now it should work !!!!

0
source

Source: https://habr.com/ru/post/1412415/


All Articles