jeudi 31 décembre 2015

How to make run app.js file on mywebsite.com?

I made an online multiplayer game. I works perfectly when I run it with node.js command prompt on localhost:3000. But I am having trouble making it run on mywebsite.com

In node command prompt i run app.js file directly but in my website my date base is looking for an index.html file. but I dont have index.html in that directory. I have it in my "public" folder. so when I go to mywebsite.com/public it runs index only but doesn't do anything with my app.js file. I would appreciate if you could help.

Here is some part of my codes:

my app.js file(myweb/app.js)

var express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server);




var usernumm = 0;
var usernum1 = [];

app.use(express.static(__dirname + '/public'));
app.use('/js',  express.static(__dirname + '/public'));

server.listen(8080,'31.170.161.96');

//

/*
app.get('/', function(req, res){
res.sendfile(__dirname + '/public/index.html');
});
*/

io.sockets.on('connection', function(socket){


var endpoint = socket.manager.handshaken[socket.id].address;
console.log('***New connection from ' + endpoint.address + ':' + endpoint.port);

usernumm++;
io.sockets.emit('usernum', usernumm);
usernum1[usernumm] =  endpoint.port;
console.log('usernum'+usernumm+'geldi'+findusernum());


socket.on('button1socket', function(){

    io.sockets.emit('button1f', findusernum() );
    console.log('user '+findusernum()+' pressed a button');

});


socket.on('disconnect', function () {
    usernumm--;
    io.sockets.emit('usernum', usernumm);
    //sockets[usernum] = socket.port;
    console.log('***Client disconnected');
});




//finds number of online users
function findusernum(){
    for(var i = 0; i<9;i++){
        if(usernum1[i] == endpoint.port){return i;}else{}
        }
}


});

and my index.html file is at (myweb/public/index.html) even if I put my index.html file in the same driectory with app.js, it is not running app.js. it is running only index codes and other js codes that are not relevant to node or socket.




Aucun commentaire:

Enregistrer un commentaire