Socket.io: module cannot be found

Asked

Viewed 81 times

2

I was here "playing" with Socket.io, all working nicely, when I gave the command node app.js overnight Nodejs gives me an error (it was working before)

Cannot find module 'socket.io'

I looked for another example on the internet I pasted and he always tells me the same thing. But when I enter the Ode by cmd and I run var foo = require('socket.io'); it finds the module without any problem.

  • Have you installed the module? You did npm install socket.io --save?

  • Yes, I installed it. I am now trying to install the module right from the application

  • No @Sergio, but I just installed the module at the right of the app

  • And now he’s found?

  • It worked, but I’m kind of "smart" maybe it’ll stop working again

  • If you used --save it gets recorded in the package.json and it will be installed when you do npm install application next time. It seems that Walker responded with the answer, if the problem was that you can accept his answer.

  • Yes, I was just waiting here for a while, but apparently it’s all in order. Right answer to him. But I will open another question because I came across another error in my app.

  • It’s a good idea to wait longer before accepting it. In this case it was simple, in more complex cases more elaborate answers may come later.

Show 3 more comments

1 answer

2


Try to install the package, in the app.js file directory, type npm install socket.io

NPM is a Nodejs package manager, to use it is simple. First, you create the manifesto of your application with the command npm init, it will ask some questions and will generate the package.json file where it will be stored among other things, the dependencies of your application.

Dependencies installed with the command npm install are saved in the node_modules directory within your project. If you add the save option (npm install --save pacote) the dependency is saved permanently in the manifest.

To install all dependencies of a package using the manifest, just run the command npm install in the directory of your application.

  • Thank you and congratulations @Walkerleite

  • @Gustavo you can also take advantage to give +1 to the answer :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.