Skip to content

Instantly share code, notes, and snippets.

@shimataro
Last active January 13, 2018 05:33
Show Gist options
  • Save shimataro/c57252f8459c9677ffe6926fe3e57b96 to your computer and use it in GitHub Desktop.
Save shimataro/c57252f8459c9677ffe6926fe3e57b96 to your computer and use it in GitHub Desktop.
Node.jsの挙動確認
// クライアントからの接続が切れたリクエストはどうなるのっと
var http = require("http");
function main(host, port)
{
http.createServer(respond).listen(port, host);
var url = "http://" + host + ":" + port + "/";
console.log("curl " + url);
}
function respond(req, res)
{
// 5秒後に応答
setTimeout(function()
{
res.writeHead(200, {"Content-Type": "text/plain"});
res.end("hell, Word\n");
}, 5000);
}
main("127.0.0.1", 3000);
// これをテンプレとしていろいろ調べる
var http = require("http");
function main(host, port)
{
http.createServer(respond).listen(port, host);
var url = "http://" + host + ":" + port + "/";
console.log("curl " + url);
}
function respond(req, res)
{
res.writeHead(200, {"Content-Type": "text/plain"});
res.end("hell, Word\n");
}
main("127.0.0.1", 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment