Last active
August 29, 2015 14:16
-
-
Save codenamejason/7468f3c88a991507710d to your computer and use it in GitHub Desktop.
Node Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is an example of an event loop server in node.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Run server from terminal | |
<code>$node nodeServer.js</code><br /> | |
-->Listening on port 8080... | |
</p><p> | |
<code>$curl http://localhost:8080</code> | |
-->Hello, this is your server... | |
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Node Server Setup | |
var http = require ('http'); | |
http.createServer(functon(request, response) { | |
response.writeHead(200); //status code in header | |
response.write("Hello, this is your server..."); //response body | |
response.end(); //close communication | |
console.log('listening on port 8080...'); | |
response.write("Node server is now running."); | |
setTimeout(function() { | |
response.write("Node server is off!"); | |
response.end(); | |
} 5000); | |
}).listen(8080); //listen for connectons on this port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment