Saturday, 27 May 2017

Access localhost:3000 through localhost/myproject/index.html

I am new to node.js and I would like to learn if I could access the node.js port (3000) by writing the url of the index.html. I followed this tutorial to create a chat app, but I have the problem I mentioned above.

I want to be able to write localhost/myproject/index.html instead of localhost:3000 on my browser.

My server-side javascript code is this:

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');
});

http.listen(3000, function(){
    console.log('listening on *:3000');
});

Is there something I should change here? Any help would be appreciated.



via Thanasis

No comments:

Post a Comment