Created
March 20, 2016 06:02
-
-
Save tyoshikawa1106/61663f78f58c3bc5ddea to your computer and use it in GitHub Desktop.
udemyの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
var http = require('http'); | |
var homepage = ` | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8'> | |
<title>Simple Server</title> | |
</head> | |
<body> | |
<h1>Server is running now!!</h1> | |
</body> | |
</html> | |
` | |
var port = process.argv[2] ? process.argv[2]:"8888"; | |
var server = http.createServer(function(request, response) { | |
response.writeHead(200, {'Content-Type': 'text/html'}); | |
response.write(homepage); | |
response.end(); | |
}) | |
server.listen(port); | |
console.log(`Server is listening http://localhost:${port}`); | |
console.log(`Press Ctrl + C to stop Server`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment