Created
November 17, 2011 16:13
-
-
Save paddybyers/1373549 to your computer and use it in GitHub Desktop.
Simple "hello world" http server for node.js
This file contains 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
console.log(process.argv[0]); | |
console.log(process.argv[1]); | |
console.log(process.argv[2]); | |
var port = process.argv.length > 2 ? Number(process.argv[2]) : 1337; | |
var http = require('http'); | |
var svr = http.createServer(function (req, res) { | |
if(req.url.indexOf('exit') != -1) { | |
res.write('exiting'); | |
res.end(); | |
svr.close(); | |
return; | |
//process.exit(0); | |
} | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.write('<h1>Hello World<\h1>'); | |
res.write('<a href="exit">exit</a>'); | |
res.end(); | |
}).listen(port, "127.0.0.1"); | |
console.log('Server running at http://127.0.0.1:' + port + '/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment