Socket.IO don't load inside TideSDK app - javascript

i created a chat app using Node.JS + Socket.IO + TideSDK, actually my Node.JS+Socket.IO server work perfectly through browser, but when a try load the server with my TideSDK app this error happend:
ReferenceError: Can't find variable: io
What's can be happend?
The code below is how i call the server.
<script src="https://mynodeserver.com/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('https://mynodeserver.com/');
</script>

Related

require is not defined on Spotify authorization code

We are doing a web using HTML and JavaScript. We have some problems when trying to do the authorization process to connect to the Spotify API.
var express = require('express'); // Express web server framework
var request = require('request'); // "Request" library
var querystring = require('querystring');
var cookieParser = require('cookie-parser')
This code we found on the internet uses require() to get some data but Chrome says:
Reference error: require is not defined.
We found that the JavaScript node may be the problem so we installed npm and Browserify but is not working.
We also used this in our HTML:
<script type="text/javascript" src="node.js"></script>
<script type="text/javascript" src="js/main.js"></script>
HELP??
What you have is the code that suppose to run on the server side. Node, Express, are server side components, and you can't run them on the clients side (inside of the browser). Server side is using 'require' to manage and load modules, that is why you have require there.
I think what should you do is to send your request to the server and server should process authentication code that you have there and send response back with the status if user authenticated or not.
require() is not an existing method for client-side JS.
Use a <script> tag then call the method after it.
This was already answered here:
Client on node: Uncaught ReferenceError: require is not defined\
Node.JS is a serverside application and you are attempting to run this clientside.
Please try using and referring to this http://requirejs.org/

Stop Phonegap from inserting Socket IO

We are building an app and we are using phonegap serve to run it as a web app. We also have a mobile version of it.
Correct me if I'm wrong but from what I've learn, phonegap is automatically inserting socket io JS into my index.html file. But we already have the socket io included via the <script></script> tag. So what happened's now is that we got 2 inclusion of socket io js.
So as for performance speaking, we only need to load the socket io once.
Screenshot
https://www.evernote.com/l/AA1k9PiF_bJM3qju6-DeE1ZLwkKV17TVyV8

Socket.io loaded with require.js is not available globally?

Why socket.io (1.0.x) loaded with require.js is not available globally? With version 0.9.x everything is working fine...
After successfull loading(with Require.js) from //cdn.socket.io/socket.io-1.0.4.js when i try connect on my node.js server i have following error:
var socket = io('http://nodeapp.herokuapp.com');
console.log(socket);
ReferenceError: io is not defined

how to install socket.io client

Is it possible to reference socket.io client library with a relative path like:
src="/socket.io/socket.io.js"
instead of
src="https://miweb:6969/socket.io/socket.io.js"
Also to connect the library we do:
var websocket = io.connect ("https://miweb.com:6969");
I have seen some do:
var websocket = io.connect ("/");
As if socket.io were running on the same port and were running on the same project.
What should I do to our server to work this way?
Yes, if your webpage is served from the same location than Socket.io, you can do this:
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('/');
socket...
</script>
But if the page is in another domain you should use an absolute url.

Run NodeJS app on appFog

All I want to do is deploy my little nodeJS app onto the free hosting site, appFog.
Nomatter what ports I set on my client side or on my server side.. I consistently get the error message:
events.js:71
throw arguments[1]; // Unhandled 'error' event
^ Error: listen EADDRINUSE
When this is on my laptop / desktop running on localhost, everything works just fine.
So this is what I've got going on:
Client side:
this.connection = new WebSocket('ws://super1onate.aws.af.cm:1337');
Server Side:
var express = require("express"); // load the express module
var app = express(); // App now holds the server object
// What ports to listen on
app.listen(process.env.VCAP_APP_PORT ||1337);
server.listen(process.env.VCAP_APP_PORT || 1337, function() {
console.log((new Date()) + " Server is listening on port " + webSocketsServerPort); });
Your server code looks ok. What is events.js? It looks like maybe you're including a module that's trying to bind to a port it shouldn't.
Once you get your server running, I don't think your client code will work. As far as I can tell, AppFog doesn't support websockets, and if it does, you'll probably want to hit port 80, not 1337.
Alright, I'm going to answer my own questions.
AppFog does not support WebSockets. websockets =/= socket.io btw fyi
Anyways, according to this site:
http://feedback.appfog.com/forums/171983-appfog/suggestions/3543100-add-websocket-support-to-node-js

Categories

Resources