I've written following code:
var http = require("http"); // http server core module
var express = require("express"); // web framework external module
var io = require("socket.io"); // web socket external module
var easyrtc = require("easyrtc"); // EasyRTC external module
var app = express();
var server = http.createServer(app).listen(app.get('port'));
io= io.listen(server,{"log level":1});
var rtc = easyrtc.listen(server, io);
this is giving following error:
$node server info - EasyRTC: Starting EasyRTC Server (v1.0.10) on
Node (v0.10.26) [TypeError: Object # has no method 'get']
TypeError: Object # has no method 'get'
at async.waterfall.pub.socketServer.sockets.on.easyrtcid (/home/ritzy1/Downloads/downloaded
codes/VEDIO/change2/testexpandwb/node_modules/easyrtc/lib/easyrtc_default_event_listeners.js:1472:29)
at fn (/home/ritzy1/Downloads/downloaded codes/VEDIO/change2/testexpandwb/node_modules/easyrtc/node_modules/async/lib/async.js:582:34)
at Object._onImmediate (/home/ritzy1/Downloads/downloaded codes/VEDIO/change2/testexpandwb/node_modules/easyrtc/node_modules/async/lib/async.js:498:34)
at processImmediate [as _immediateCallback] (timers.js:330:15)
Ηow can i fix it?
You have to give a specific port number in the listen() function.
Change the following line var server = http.createServer(app).listen(app.get('port')); with var server = http.createServer(app).listen(8080); Note : 8080 is a port number you can specify any other port number which are not currently using.
Happy coding
Related
Whenever I try to emit to room I get this error message on my server:
TypeError: Object #<Manager> has no method 'in'
at Query.<anonymous> (/root/server.js:553:19)
at /root/node_modules/mongoose/node_modules/kareem/index.js:177:19
at /root/node_modules/mongoose/node_modules/kareem/index.js:109:16
at process._tickCallback (node.js:419:13)
My code:
var socketio = require('socket.io');
var router = express();
var server = http.createServer(router);
var io = socketio.listen(server);
io.in(room).emit("inGame",Date.now()+10000);`
Okay so I found the problem. for any people who get this problem in the future
make sure you use the latest version of socket.io. before updating check your package.json to see if socketio is written to install a older version remove r update the version in the package.json.
I've an application in node.js with socket.io. Everything was running completely fine, but suddenly the browser started to send this error.
failed: Error in connection
establishment:net::ERR_TUNNEL_CONNECTION_FAILED
I didn't make any code change.
The protocol used by socket is ws:// and when I try to use this url in browser
'ws://highgarden-nodejs-91180.sae1.nitrousbox.com/socket.io/?EIO=3&transport=websocket&sid=T9Unec8KbWw-GAL8AAAF'
Chrome returns this error:
Failed to load resource: net::ERR_DISALLOWED_URL_SCHEME
This is a part of the socket setup code:
server.js:
var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);
var port = process.env.PORT || 3000
*------------------------------------------*
// routes ===
var routes = require('./config/routes.js');
var sock = {}
routes(app, passport, sock);
io.sockets.on('connection', sock.update);
// launch ===
server.listen(port);
Thanks advance.
Hi the exception ERR_TUNNEL_CONNECTION_FAILED happens when a tunnel connection through the proxy could not be established. And the ERR_DISALLOWED_URL_SCHEME happens when the scheme of the URL is disallowed.
May you need use it behind the proxy!
Chrome 45.0.2454.101 m says the page has been disabled or moved on the server.
I'm trying to make a NodeJS http-proxy with a Router Table.
I saw some examples using http-proxy and try like this :
var httpProxy = require('http-proxy');
var proxyTable = {};
proxyTable['testproxy.com/toto'] = 'google.com:80';
proxyTable['testproxy.com/tata'] = 'gmail.com:80';
var httpOptions = {
router: proxyTable
};
console.log('Proxy Server Listening on port 80');
console.log('Requests to textproxy.com/toto (on port 80) are redirected to google.com:80');
console.log('Requests to textproxy.com/tata (on port 80) are redirected to gmail.com:80');
httpProxy.createServer(httpOptions).listen(80);
FYI : testproxy.com refer to 127.0.0.1.
It seems to work (it only intercepts request to testproxy.com/toto and tata) but when I try :
curl http://testproxy.com/toto
I have a NodeJS error :
var proxyReq = (options.target.protocol === 'https:' ? https : http).reque
^
TypeError: Cannot read property 'protocol' of undefined
at Array.stream [as 3] (D:\workspace\Proxy W_S\node_modules\http-proxy\l
ib\http-proxy\passes\web-incoming.js:103:35)
at ProxyServer.<anonymous> (D:\workspace\Proxy W_S\node_modules\http-pro
xy\lib\http-proxy\index.js:83:21)
at Server.closure (D:\workspace\Proxy W_S\node_modules\http-proxy\lib\ht
tp-proxy\index.js:125:43)
at Server.EventEmitter.emit (events.js:98:17)
at HTTPParser.parser.onIncoming (http.js:2108:12)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23
)
at Socket.socket.ondata (http.js:1966:22)
at TCP.onread (net.js:525:27)
Is router table already supported by http-proxy module ?
I have to do a dynamic proxy, any idea ?
I'm new at NodeJS, and I'm stuck.
Thanks a lot for your answers.
Pierre-Luc
It seems that proxy table routing was removed from node-http-proxy when they released version 1.0.0.
However, they provided a new way of doing it using the new API:
https://blog.nodejitsu.com/node-http-proxy-1dot0/
While trying to execute server.js program I am getting the following error:
var app = express();
Type error: object is not a function
at object.<anonymous>
even tried re installing and changing the version of express to
npm install
npm uninstall express
npm install express#2.5.9
but it resulted in new error
fqdn = ~req.url.indexof(' ://')
I use windows and i am working on node.js version 0.8.4.
If you're using Express < 3.0, the return value of require('express'); is not a function; you'll need to create a server the old way.
Express 2.x
var express = require('express');
var server = express.createServer();
Express 3.x
var http = require('http');
var express = require('express');
var app = express();
var server = http.createServer(app);
What does
> require('express').version;
'3.0.0rc2'
return?
As you can see it does return 3.0.0rc2? Does yours really return 2.5.9. if it does you use like Brandon said 2.x section. If it returns 3.x you use his 3.x section.
I have a number of nodejs applications running on Express using the code below. They all run fine using code similar to the following:
fs = require 'fs'
https = require 'https'
express = require 'express'
server_port = 3000
keys_dir = 'keys/' server_options = {
key : fs.readFileSync(keys_dir + 'privatekey.pem'),
cert : fs.readFileSync(keys_dir + 'certificate.pem') } app = express.createServer(server_options)
app.listen server_port
console.log "HTTPS Server started on port #{server_port}"
However, when trying to create a new application using this code I see a ERR_SSL_PROTOCOL_ERROR when starting the https server. Any idea what is causing this problem?
I discovered that was caused when moving from express 2.5.8 to express 3 - specifically 3.0.0beta4. When creating a new project the version pulled from npm had changed to the version 3 series. Even though the module is marked as "beta" when you run express --version this version is what is installed now when running npm install express. The details of the changes are outlined here.
To solve this for my case I used the following code:
const fs = require("fs");
const https = require("https");
const express = require("express");
const keysDir = "keys/";
const options = {
key : fs.readFileSync(keysDir + "privatekey.pem"),
ca : fs.readFileSync(keysDir + "certrequest.csr"),
cert : fs.readFileSync(keysDir + "certificate.pem")
};
const app = express();
https.createServer(options, app).listen(3000);