sdfds dffdsf
sdfds dffdsf

Reputation: 61

Cannot find module 'socket.io' after global install

I try to use socket io so I follow they tutorial in here. I did:

 var app = require('express')();

And I get this error:

Error: Cannot find module 'express'

Before running I did in the command line:

npm install --save [email protected]

Like described in they tutorial. So I search for that and I find this answer node.js, Error: Cannot find module 'express'

So I did like the first answer:

 npm install express

And now I get this error:

Error: Cannot find module 'socket.io'

So I search again and I found that I need to install its globaly (Error: Cannot find module 'socket.io' first answer)

So I did:

 npm install -g socket.io

But still the same error again.

What should I do?

Upvotes: 0

Views: 394

Answers (1)

gnerkus
gnerkus

Reputation: 12019

You do not need to install express or socket.io globally.

The error is the result of Node being unable to find the express module in your local npm registry; the package.json file. You need to create a package.json file in the root of your project.

Navigate to the root of the directory and run:

npm init

The command npm init creates the package.json file. Any subsequent installs with the --save option will install the module and register it in the package.json.

Upvotes: 1

Related Questions