I'm using nodejs as a server for a videogame, and i want to try the multiplayer part but, I can not connect from outside my computer via localhost.
So, I used express before and this worked:
var app = express();
var serv = app.listen(8081, "127.0.0.1");
Above, the server is using localhost(127.0.0.1), but it can be changed to whatever IP I want. And is listening to port 8081.
The problem is, I'm no longer using express, only Nodejs. I'm handling the request, respond and handlers "manually". I researched a little on the documentation of express here:
http://expressjs.com/es/4x/api.html#app.use
But honestly, I did not understand how this function work.
This is my server.js:
// Import the necessary modules
var http = require('http');
// Server object
server = {};
// Start the http server
server.httpServer = http.createServer(function(req, res){
/* Stuff */
}
// Start the server
server.httpServer.listen(8081, function(){
console.log('The server is listening on port 8081');
});