Created
June 24, 2017 12:30
-
-
Save TakizawaAkira/3fdfd39efbd1a26c6f57c1ddc92b4b88 to your computer and use it in GitHub Desktop.
node-server
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
const http = require('http'); | |
const hostname = '127.0.0.1'; | |
const port = 3000; | |
var server = http.createServer(); | |
server.on('request', doRequest); | |
// ファイルモジュールを読み込む | |
var fs = require('fs'); | |
// リクエストの処理 | |
function doRequest(req, res) { | |
// ファイルを読み込んだら、コールバック関数を実行する。 | |
fs.readFile('./index.html', 'utf-8' , doReard ); | |
// コンテンツを表示する。 | |
function doReard(err, data) { | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.write(data); | |
res.end(); | |
} | |
} | |
server.listen(port, hostname, () => { | |
console.log(`Server running at http://${hostname}:${port}/`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment