Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM - Can't install socket.IO

I am trying to install socket.io on windows with npm for use on a nodeJS server.

First, when I typed "npm install socket.IO" i had an error in the log saying something about python and node-gyp. I installed python 2.7.3 and set the environment variables.

Now I got a new error, which has something to do with visual studio (what the hell does VS have to do with npm ? Is it about the compiler? ).

The error is the same as here npm install for some packages (sqlite3, socket.io) fail with error MSB8020 on Windows 7 But when I use the option in the answer instead of the error it tells me something about a possible data loss (c4267) but doesn't log any error.

Then when I start my app, it tells me cannot find module socket.io still What could this come from ?

Oh and also when i do npm config get root it tells me "undefined" could it have anything to do with it ? Should I install the modules globally or locally ?

like image 633
user2316341 Avatar asked May 09 '13 18:05

user2316341


People also ask

Why npm install is not working?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

How do I run a Socket.IO in node JS?

In order to do it, you need to create an index. js file and install socket.io and express. You can use the following command: touch index. js && npm install express socket.io && npm install --save-dev nodemon .

Does Socket.IO need node JS?

It requires almost no basic prior knowledge of Node.JS or Socket.IO, so it's ideal for users of all knowledge levels.

What is Socket.IO npm?

Socket.IO is a library that enables low-latency, bidirectional and event-based communication between a client and a server. It is built on top of the WebSocket protocol and provides additional guarantees like fallback to HTTP long-polling or automatic reconnection.


1 Answers

At least one of the packages in Socket.IO's dependency tree is a C/C++ addons which needs to be compiled on your system as it's installed. And, since it's a dependency, if it doesn't succeed in installing, neither will Socket.IO.

To enable cross-system compilation, Node.js uses node-gyp as its build system. You'll need to have it installed as a global package:

npm install -g node-gyp

As well as have its dependencies installed. Abridged version:

  • Python 2
  • C/C++ Compiler / Build Tools
    • For Windows, Microsoft Visual Studio 2013 (C++ or Windows Desktop) (Express edition)
      • For 64-bit, may need Windows 7 64-bit SDK

Then, you should be able to install Socket.IO as a local package so you can require it:

npm install socket.io
like image 141
Jonathan Lonowski Avatar answered Oct 07 '22 12:10

Jonathan Lonowski