This is the error message I am getting in the web console on my live node.js heroku app: polling-xhr.js:264 GET http://localhost:3000/socket.io/?EIO=3&transport=polling&t=M2MDZUw net::ERR_CONNECTION_REFUSED
When I run my program locally, it all works fine without any problem. I have listed the server to listen to whatever is in the environment PORT
or port 3000
if there's nothing there. Below is my relevant server.js
code, and package.json
code, as well as the client code used to connect to the server.
server.js
var express = require("express");
var socket = require("socket.io");
var app = express();
var server = app.listen(process.env.PORT || 3000)
package.json
{
"name": "testProject",
"version": "1.0.0",
"description": "test project using node.js + sockets.io",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"sockets",
"p5",
"node"
],
"author": "henry zhu",
"license": "ISC",
"dependencies": {
"express": "^4.16.2",
"socket.io": "^2.0.4"
}
}
Client-side code to connect to server:
var socket = io.connect("http://localhost:3000");
The version of socket.io I am using client side is 2.0.4.