NodeJS – how to install Socket.IO

This week my focus at work has shifted slightly away from Grasshopper and back into the world of web development, server communications and associated tasks. For part of my work, I created some test files to play about with sockets in Javascript (the bigger picture is to use sockets to communicate between some C# code and Javascript, but that’s for a later post). To do this, I had to install Socket.IO as part of the NodeJS package, but ran into a couple of difficulties. Having now resolved those difficulties, I thought I’d share what went wrong and how I solved them, so that in the future if I try this again I already have solutions to hand, or perhaps it’ll help you if you’re stuck with the same issues.

Issue one – invalid version

The first issue I had was with the package.json file I created which outlined my project. In this file, I had a line which detailed the version number of my project, which was originally:
“version”: “0.1”,
Unfortunately, when then trying to install Socket.IO, it didn’t like this notation (number dot number). It wants it be in a different notation, namely (number dot number dot number) – 0.0.1 (for example).

When I modified my package.json file to have the version number read 0.0.1, Socket.IO resolved this issue (and moved onto the second issue – if you don’t have the second issue, Socket.IO should install).

Issue two – invalid path to ‘git’

The second issue was with a lack of ‘git’ in the system PATH variable. When installing Socket.IO, it isn’t made obvious that you need to install GitHub, but when you work out why it needs it and how the NodeJS package is distributed, it does make sense. Luckily fixing this error is simple, you just need to add your GitHub folder to the PATH variable.

The first this you need to do is get the file location of your GitHub cmd folder. This does of course require that you have GitHub installed, so if you haven’t done that yet, I’d strongly recommend you do so.

The GitHub cmd folder is usually found in “C:/Users/(your_username)/AppData/Local/GitHub/PortableGit_(guid)/cmd”.

You need to replace (your_username) with your system username and (guid) with the Guid associated to your GitHub install. It might not be easy to find that, do you could always navigate to the GitHub folder in your Local AppData, and then click-through to the PortableGit folder.

After you have this location, you need to add it to your PATH variable. In Windows, you can do this by navigating to the Environmental Variable Editor (instructions for various operating systems are available here), finding the PATH variable in the ‘System Variables’ section and clicking ‘Edit’.

When the edit box pops up (should look like something below), you can prepare to paste your location in at the end. Warning – please remember to put in a semicolon at the end of the current path, BEFORE you paste in the GitHub location! When you’ve put your semicolon in at the end of the current string, you’re clear to paste the location of the GitHub cmd folder. Do NOT put a semicolon at the end of the GitHub location unless you’re adding another location now or later. If the GitHub cmd is the last variable, do not put a semicolon in.

Changing the PATH variable

Changing the PATH variable

Click ok when you’ve finished and save the properties in the usual way and viola, the git variable can now be used in the command line. If you type git into the terminal, it will give you the git help file if you set the PATH variable correctly.

After this, Socket.IO should successfully install (providing you don’t have another issue lurking…)! If you encounter a different error or have a different solution to the issues above, feel free to post a comment. Happy socketing!

Leave a Reply

Your email address will not be published. Required fields are marked *