How to make a server?

I'm trying to learn how to use socket.io with phonegap/cordova. The tutorials teach how to use node.js on cmd, but nothing for how to initiate this on my website server.

 var http = require('http');
 var server = http.createServer(function(request, response){
     console.log('Connection');
     response.writeHead(200, {'Content-Type': 'text/html'});
     response.write('hello world');
     response.end();
 });

server.listen(8001);

I have this code so far which I can run via "node server.js" and connecting to http://localhost:8001 will show "hello world". How do I do this on something such as HostMonster? I'm fairly new to programming and can't quite comprehend this. Also, if you happen to know any good socket.io tutorials that explain things in full detail, would be greatly appreciated! Thanks!


That's a code just to create a simple webserver in nodejs, nothing to do with socket.io (which is a library for nodejs). To run nodejs in a server you need an hosting who supports that and apparently HostMonster does not support node.js Some easy place to start hosting node.js apps you can look here https://www.quora.com/What-are-some-alternatives-to-Heroku-that-are-more-reliable heroku is probably the easiest.

For socket.io you can directly reffer to their website which other than having documentation they have demos and getting started example. http://socket.io/get-started/chat/

链接地址: http://www.djcxy.com/p/44742.html

上一篇: jQuery Mobile是否准备好用于生产?

下一篇: 如何制作服务器?