1
I have a problem to initiate the nodejs in the server Azure, I’ve set everything up and the site is already in the air, but I have a chat in Ode, using socket.io, see the code below (index.js):
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use(express.static(__dirname + '/'));
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
var user = 0;
io.on('connection', function(socket){
user = user +1;
console.log(user);
socket.on('disconnect', function(){
user = user -1;
console.log(' has disconnected from the chat.');
console.log(user);
});
socket.on('chat message', function(msg,nome,cor){
io.emit('chat message', msg,nome,cor);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
index.html
var socket = io();
var cor = randomColor();
$('form').submit(function(){
socket.emit('chat message', $('#m').val(),Cookies.get('name'),cor);
$('#m').val('');
return false;
});
socket.on('chat message', function(msg,nome,cor){
$('#messages').append($('<li style="background:'+cor+'">').text(msg));
$('#messages').append($('<p class="mensagem">').text(nome));
});
socket.on("disconnect", function(){
console.log("client disconnected from server");
});
No Zure, no cmd, already installed the necessary modules (socket.io, express)
now when I type Node index.js it gives a BAD REQUEST error.
Can someone help us? Thank you.