Download and Install Node.js
We can download Node.JS server for windows from here . Nothing to configure... Just download and install it. You can check whether you have installed it correctly using command prompt. Type node and press Enter you will get the node prompt. Host the sample script
This is the sample code for hello world server.
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/');
Create new text file and save above code as sample.js Run Sample Server
Then go to your folder (using command prompt) which has the sample.js file and execute it using node by executing command node sample.js
Access It Using Browser Open your browser and enter the address we have given in the sample.js file.
That's It !
I will go more detail in to node.js and socket.io in the next post :).
this is awesome example
ReplyDeleteThanks,
ReplyDeleteIt is really helpful to me.
Hi nice and useful article. However, it ios working fine when I access the url on the same machine, when browsing from another machine i get "This page can't be displayed in spite of the fact that I cnaged 127.0.0.1 by machine IP
ReplyDeleteYou may need to open connections form the external http requests. In windows you may need to open the firewall. I'm not sure how it will work on IOS.
Delete