Socket.IO/Node.JS execution

I'm new to both Node.JS and Socket.IO, so I decided to pick up a simple chat client as my first project. To my knowledge, it structured correctly, but I'm being thrown an object expected error whenever I try to run index.js. Anyone know what's up? (if it helps, I'm running on Windows 8.1)

Code:

Index.html

<!doctype html> <html> <head> <title>TNjs Chat</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font: 13px Helvetica, Arial; } form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } #messages { list-style-type: none; margin: 0; padding: 0; } #messages li { padding: 5px 10px; } #messages li:nth-child(odd) { background: #eee; } </style> </head> <body> <ul id="messages"></ul> <form action=""> <input id="m" autocomplete="off" /><button>Send</button> </form> <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script> <script src="http://code.jquery.com/jquery-1.11.1.js"></script> <script> var socket = io(); $('form').submit(function(){ socket.emit('chat message', $('#m').val()); $('#m').val(''); return false; }); socket.on('chat message', function(msg){ $('#messages').append($('<li>').text(msg)); }); </script> </body> </html>

index.js

var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); io.on('connection', function(socket){ socket.on('chat message', function(msg){ io.emit('chat message', msg); }); }); http.listen(3000, function(){ console.log('listening on *:3000'); });

package.json

{ "name": "TNjsChat Client", "version": "0.0.1", "description": "A browser based chat system using Node.JS and socket.io, by Touka", "dependencies": { "express": "4.10.2", "socket.io": "1.2.0" } }

-------------Problems Reply------------

You need to run node, not just let Microsoft IE run the js file which is what your screenshot seems to show.

Make sure node.exe is in the path somewhere and then run "node index.js" from the index.js directory and make sure all modules you need (like Express) are installed properly and available from the index.js directory.

Category:javascript Views:3 Time:2017-04-23

Related post

  • LearnBoost's Socket.IO-Node why onClientMessage not work 2010-06-06

    I tried to put the module "LearnBoost's Socket.IO-Node", all works, except event 'onClientMessage' Tell, in what there can be a problem, thanks! ...sorry for my english io.listen(server, { onClientConnect: function(client){ client.send(json({ buffer:

  • Using a Flash socket with Node.js 2010-09-03

    I've been using gimite / web-socket-js to implement a WebSocket past simply Chrome and development builds of Safari. I want to move away from the Ruby server and onto Node.js. Suddenly it doesn't work in anything but Chrome. I suspect that this has t

  • Sending data only to chosen users using Socket.io-node 2011-02-09

    Is it possible to send data using socket.io-node just to chosen group of users? For example, how could I implement chat with different rooms? I dont want .broadcast() to send data to all logged in users. --------------Solutions------------- Normally

  • Cannot find module 'Socket.IO-node' when trying to run node.js boilerplate project 2011-07-06

    I'm getting an error when I try to run a project created with the node.js boilerplate project I've installed socket.io using NPM with this command: npm install socket.io The error I'm getting is: node.js:189 throw e; // process.nextTick error, or 'er

  • How to uniquely identify a socket with Node.js 2011-07-24

    TLDR; How to identify sockets in event based programming model. I am just starting up with node.js , in the past i have done most of my coding part in C++ and PHP sockets() so node.js is something extremely new to me. In c++ to identify a socket we c

  • multiuser paint app with html5 canvas socket.io node.js 2012-01-16

    I am doing kind of multi-user application with html5 canvas, socket.io, node.js Over now I am using broadcast to send canvas state to others, but I can see that there is sometimes kind of race: Changing stroke properties(like color or lineWidth) in o

  • website using WebG, HTML5, MongoDB, Three.js, Socket.IO, Node JS requires chrome or firefox, why? 2013-06-27

    website http://hererightnow.org/ website states using the following technologies: WebG, HTML5, MongoDB, Three.js, Socket.IO, Node JS requires chrome or firefox only. It is not functioning using IE9. Ideas for a workaround. --------------Solutions----

  • Socket.IO / Node.JS / Rails 3 / IE 2010-09-29

    This is a bit complicated but here goes. I have a Rails app that has a small JS widget that gets updated on some backend processing stuff. The Rails app queues up a job in Redis (via Kthxbye) which gets processed and then once completed, fires off a

  • Socket.IO / node.js problem: unintended disconnects 2011-02-19

    I see this sort of thing in my node log fairly frequently: 19 Feb 13:50:20 - Initializing client with transport "flashsocket" 19 Feb 13:50:20 - Client 5846663371194154 connected 19 Feb 13:50:20 - Client 5846663371194154 disconnected It seems to happe

  • Socket.io Node.js error in IE7 - Access Denied 2011-03-02

    I am using socket.io to connect to my node server using the following script: $socket = new io.Socket(null,{port:8086,rememberTransport:false}); $socket.connect(); If works fine in IE8/9, Chrome, Safari & FF. When I try it in IE7, a connection is

  • socket with node js example 2011-03-30

    Hi all i have problem.... Client side code <html> <body onload="fun()"> <script src="C:\cygwin\usr\local\lib\node\.npm\socket.io.6.16\package\support\socket.io-client\socket.io.js"></script> <script> function fun() { ale

  • Rails and Socket.io (node.js) 2011-04-05

    I intend to use a Rails app to serve real-time data processed by a node.js server and Socket.io. In the Socket.io website, it says that: If you won't leverage Node.JS to serve your files, make sure to set the global WEB_SOCKET_SWF_LOCATION to the loc

  • Memory Leak with socket.io + node.js 2011-06-24

    I appear to have a memory leak with my node application. I built it quickly, and my JavaScript isn't too strong, so this might be easy. I've done some heap dumps on it, and it's the String 'object'? leaking memory, at the rate of about 1MB every 5 mi

  • Formatting messages to send to socket.io node.js server from python client 2011-07-14

    I'm trying to get a python client talking to a node.js server using socket.io 0.7, by sending a custom event to the server. Based on the socket.io reference I have found here: https://github.com/LearnBoost/socket.io-spec, and the following websocket

  • zombie.js and socket.io (node.js) 2011-08-16

    I would like to test my node.js/socket.io application using the zombie.js headless browser. Unfortunately when the zombie.js app connects to my app it reports a load of connection/disconnection events. Eg. Zombie: Firing timeout 234, delay: 1000 Zomb

  • Node.js + socket.io + node-amqp and queue binginds when "re" connecting thru socket.io 2011-09-29

    I have one scenario which is very close to this sample: One main screen: this screen (client side) will connect to the socket.io server thru server:9090/scope (io.connect("http://server:9090/scope)) and will send one event "userBindOk" (socket.emit("

  • Can't connect and getting a "unhandled socket.io url" error with MAMP + Socket.io (node.js) 2011-10-16

    I'm developing an application using CodeIgniter on a MAMP server (for development, live it'll be on LAMP). I'm trying to add the real-time functionality of socket.io for a chat server, but I'm having some issues. I have socket.io and MAMP up and runn

  • javascript - Server not handle event (socket.io/node.js) 2012-01-21

    I've just started with Node.js/ Socket.io and want to build an sample app in which: When connected, both server and client print 'connected!'. Everytime client submit a message, server print content and respond back to client. Here is my code: NodeJS

  • Realtime application - alternative for socket.io (node.js) 2012-03-21

    I use node.js. I am looking for an alternative for socket.io. I need to send a private message to the user. What is the alternative for the SOCKET.IO? --------------Solutions------------- You haven't really explained why you're looking for Socket.IO.

  • How to send message from one socket.io node application to other socket.io node application 2013-04-29

    In my node application I need to send message to other node application using socket.io. Because depending upon the first application results I need to do some tasks in second application. How can I do this? var express=require('express'); var http=r

  • how to keep alive a socket in node.js in appfog 2013-06-16

    I have a long running socket which I need to keep alive even when the system is idle. For that I have tried everything from reduced long polling duration to a server and client ping pong messages but, nothing seems to work as the socket gets disconne

  • Cross-browser BSD-style sockets or Node.js streams 2013-06-27

    I'm in the process of implementing a streaming protocol in JavaScript. The protocol is defined in terms of byte streams, not messages. I'd like to be able to talk to browsers using this protocol. I've used Socket.io in the past for easy cross-browser

  • How to listen to a random tcp socket in node.js 2010-08-18

    I know I can create a tcp server like that in node.js var dataServer = net.createServer(function (stream) { }); dataServer.on("listening", function() { // this data server listen to a random port // but how can I get the number of port console.log(da

  • Socket.io/node.js on local network? 2011-09-19

    I have two machines on the same network say at 192.168.1.2 and 192.168.1.3. 192.168.1.2 = server/dev pc 192.168.1.3 = client/browser pc So on the server/dev pc I have a socket.io/http server running on port 82 On the client server I'm using chrome as

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.149 (s). 11 q(s)