I'm running a nodejs application on my virtual host. I just want to see the results of my index.js port 3000 on browser (I have tested all open ports) , but I will get connection time out with domain or server Ip.
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var message = 'It works!\n',
version = 'NodeJS ' process.versions.node '\n',
response = [message, version].join('\n');
res.end(response);
});
server.listen(3000,function(){
console.log("Listening on port : " 3000);
});
And I will start with node index.js
I can see the results with ssh command
curl https://localhost:3000
But when I can't see the results in browser Any idea for this?
CodePudding user response:
You trying to access server via https protocol, however your server supports http
CodePudding user response:
You need to use the default port by node js and the code you need to write is as follows
server.listen(3000 || process.ENV.PORT,function()
{
console.log("Listening on port : " process.ENV.PORT);
});