{"id":1111,"date":"2014-07-02T21:25:06","date_gmt":"2014-07-02T12:25:06","guid":{"rendered":"http:\/\/www.nightmare-yk.com\/?p=1111"},"modified":"2016-02-23T09:11:08","modified_gmt":"2016-02-23T00:11:08","slug":"node-js-%e7%ac%ac2%e5%bc%behttp%e3%82%b5%e3%83%bc%e3%83%90%e3%82%92%e7%ab%8b%e3%81%a1%e4%b8%8a%e3%81%92","status":"publish","type":"post","link":"http:\/\/www.nightmare-yk.com\/?p=1111","title":{"rendered":"Node.js \u7b2c2\u5f3e(HTTP\u30b5\u30fc\u30d0\u3092\u7acb\u3061\u4e0a\u3052)"},"content":{"rendered":"<p>\u3084\u3063\u3068\u3001Node.js\u306e\u8a18\u4e8b\u3092\u66f8\u304d\u307e\u3059\uff01<br \/>\n\u65e9\u304f\u30821\u5e74\u8fd1\u304f\u7d4c\u904e\u3057\u3066\u3044\u308b\u6c17\u304c\u3057\u307e\u3059\u304c\u3001\u6c17\u306e\u305b\u3044\u3067\u3059r(^\u03c9^*)<\/p>\n<p>Node.js\u306fHTTP\u30b5\u30fc\u30d0\u30fc\u3084HTTP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u5b9f\u88c5\u3057\u305fhttp\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u306a\u306e\u3067\u3001web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3059\u308b\u969b\u306b\u306f\u3001\u3053\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u542b\u307e\u308c\u3066\u3044\u308bhttp.Server\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u65e9\u901fHTTP\u30b5\u30fc\u30d0\u3092\u7acb\u3066\u3066\u307f\u307e\u3057\u3087\u3046\uff01\uff01<br \/>\n\u6700\u521d\u306f\u300cHello World\u300d\u3068\u8868\u793a\u3057\u3066\u307f\u307e\u3059\u3002\u304a\u306a\u3058\u307f\u3067\u3059\u306d(\uff61-_-\uff61 )\uff89<\/p>\n<p>1008\u756a\u30dd\u30fc\u30c8\u3092\u5229\u7528\u3057\u3066HTTP\u30b5\u30fc\u30d0\u306e\u5f85\u3061\u53d7\u3051\u3092\u958b\u59cb\u3059\u308b\u306b\u306f\u6b21\u306e\u3088\u3046\u306b\u6307\u5b9a\u3057\u307e\u3059\u3002\u300c\/\/\u300d\u3067\u66f8\u3044\u3066\u3042\u308b\u90e8\u5206\u306f\u30b3\u30e1\u30f3\u30c8\u306b\u306a\u308a\u307e\u3059\u3002\u4e00\u5fdc\u3069\u306e\u3088\u3046\u306a\u51e6\u7406\u3092\u3057\u3066\u3044\u308b\u304b\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre>\r\n$ vi test.js\r\n\uff5e\r\n\/\/ HTTP\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u547c\u3073\u51fa\u3057\r\nvar http = require('http');\r\n\r\n\/\/ http.Server\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u4f5c\u6210\r\nvar server = http.createServer();\r\nserver.on('request', function (request, response) {\r\n\r\n  \/\/ \u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9200\u3067HTTP\u30ec\u30b9\u30dd\u30f3\u30b9\u30d8\u30c3\u30c0\u3092\u51fa\u529b\u3059\u308b\r\n  response.writeHead(200, {'Content-Type': 'text\/plain'});\r\n\r\n  \/\/ Hello World\u3068\u8868\u793a\u3057\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u7d42\u4e86\r\n  response.end('Hello World\\n');\r\n});\r\n\r\n\/\/ listen\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u884c\u3057\u3001\u5f85\u3061\u53d7\u3051\u958b\u59cb(1008\u756a\u30dd\u30fc\u30c8)\r\nserver.listen(1008);\r\n\r\n\/\/ \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30ed\u30b0\u3092\u51fa\u529b\r\nconsole.log('Server running at http:\/\/www.nightmare-yk.com:1008\/');\r\n\uff5e<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u3053\u308c\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002\u3042\u3063\u3001\u3061\u306a\u307f\u306bforever\u306fnode.js\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u30c7\u30fc\u30e2\u30f3\u5316\u3059\u308b\u30c4\u30fc\u30eb\u3067\u3059\u3002\u3053\u308c\u306f\u3001\u6700\u5f8c\u306b\u8aac\u660e\u3092\u3057\u307e\u3059(\uff4f\uffe3\u2200\uffe3)\u30ce<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre>\r\n# forever test.js\r\nwarn:    --minUptime not set. Defaulting to: 1000ms\r\nwarn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms\r\nServer running at http:\/\/www.nightmare-yk.com:1008\/\r\n<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u3061\u3083\u3093\u3068\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u8a2d\u5b9a\u3057\u305f\u30ed\u30b0\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u306d\uff01<br \/>\n\u30d6\u30e9\u30a6\u30b6\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.nightmare-yk.com\/wp-content\/uploads\/2014\/07\/node.js\u753b\u9762.png\"><img data-attachment-id=\"1140\" data-permalink=\"http:\/\/www.nightmare-yk.com\/?attachment_id=1140\" data-orig-file=\"https:\/\/i0.wp.com\/www.nightmare-yk.com\/wp-content\/uploads\/2014\/07\/node.js\u753b\u9762.png?fit=629%2C255\" data-orig-size=\"629,255\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"node.js\u753b\u9762\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.nightmare-yk.com\/wp-content\/uploads\/2014\/07\/node.js\u753b\u9762.png?fit=300%2C121\" data-large-file=\"https:\/\/i0.wp.com\/www.nightmare-yk.com\/wp-content\/uploads\/2014\/07\/node.js\u753b\u9762.png?fit=629%2C255\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.nightmare-yk.com\/wp-content\/uploads\/2014\/07\/node.js\u753b\u9762.png?resize=629%2C255\" alt=\"node.js\u753b\u9762\" width=\"629\" height=\"255\" class=\"aligncenter size-full wp-image-1140\" srcset=\"https:\/\/i0.wp.com\/www.nightmare-yk.com\/wp-content\/uploads\/2014\/07\/node.js\u753b\u9762.png?w=629 629w, https:\/\/i0.wp.com\/www.nightmare-yk.com\/wp-content\/uploads\/2014\/07\/node.js\u753b\u9762.png?resize=300%2C121 300w\" sizes=\"(max-width: 629px) 100vw, 629px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>apache\u7b49\u306eWeb\u30b5\u30fc\u30d0\u3092\u4e0a\u3052\u308b\u5fc5\u8981\u304c\u306a\u304f\u3001\u7c21\u5358\u3067\u3059\u306d\u30fd( \u00b4 \u25bd ` )\uff89<\/p>\n<p><span style=\"color: #7b68ee;\">\u25a0 forever\u30b3\u30de\u30f3\u30c9<\/span><br \/>\nforever\u30b3\u30de\u30f3\u30c9\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre>\r\n# npm install forever -g\r\nnpm http GET https:\/\/registry.npmjs.org\/forever\r\nnpm http 200 https:\/\/registry.npmjs.org\/forever\r\n:\r\n:\r\n<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u5b9f\u969b\u306b\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\uff01<br \/>\n\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u6c38\u7d9a\u7684\u306b\u8d77\u52d5\u3059\u308b\u65b9\u6cd5\u306f\u4ee5\u4e0b\u3067\u3059\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre>\r\n# forever start test.js\r\nwarn:    --minUptime not set. Defaulting to: 1000ms\r\nwarn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms\r\ninfo:    Forever processing file:\r\n<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u8d77\u52d5\u3067\u304d\u305f\u304b\u78ba\u304b\u3081\u308b\u305f\u3081\u3001\u6c38\u7d9a\u7684\u306b\u8d77\u52d5\u3057\u305f\u30a2\u30d7\u30ea\u4e00\u89a7\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre>\r\n# forever list\r\ninfo:    Forever processes running\r\ndata:        uid  command       script   forever pid  logfile                 uptime\r\ndata:    [0] cGtT \/usr\/bin\/node test.js 4303    4305 \/root\/.forever\/cGtT.log 0:0:0:57.294\r\n<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u8d77\u52d5\u3067\u304d\u3066\u3044\u307e\u3059\u306d\u2606<br \/>\n\u8d77\u52d5\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4e00\u89a7\u306e0\u756a\u76ee\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u30010\u3092\u6307\u5b9a\u3057\u3066\u30a2\u30d7\u30ea\u3092\u7d42\u4e86\u3055\u305b\u307e\u3059\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre>\r\n# forever stop 0\r\ninfo:    Forever stopped process:\r\ndata:        uid  command       script   forever pid  logfile                 uptime\r\n[0] cGtT \/usr\/bin\/node test.js 4303    4305 \/root\/.forever\/cGtT.log 0:0:1:50.108\r\n<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u3069\u3046\u3067\u3057\u305f\u3067\u3057\u3087\u3046\u304b\uff1f<br \/>\n\u6b21\u306f\u3088\u308a\u5b9f\u8df5\u7684\u306a\u66f8\u304d\u65b9\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059(*^\u25bd^*)\uff89<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"http:\/\/www.nightmare-yk.com\/?p=1111\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"http:\/\/www.nightmare-yk.com\/?p=1111\" ><\/g:plusone><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>\u3084\u3063\u3068\u3001Node.js\u306e\u8a18\u4e8b\u3092\u66f8\u304d\u307e\u3059\uff01 \u65e9\u304f\u30821\u5e74\u8fd1\u304f\u7d4c\u904e\u3057\u3066\u3044\u308b\u6c17\u304c\u3057\u307e\u3059\u304c\u3001\u6c17\u306e\u305b\u3044\u3067\u3059r(^\u03c9^*) Node.js\u306fHTTP\u30b5\u30fc\u30d0\u30fc\u3084HTTP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u5b9f\u88c5\u3057\u305fhttp\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u306a\u306e\u3067\u3001web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3059\u308b\u969b\u306b\u306f\u3001\u3053\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u542b\u307e\u308c\u3066\u3044\u308bhttp.S [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[3],"tags":[167,168,99],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/posts\/1111"}],"collection":[{"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1111"}],"version-history":[{"count":11,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/posts\/1111\/revisions"}],"predecessor-version":[{"id":1144,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/posts\/1111\/revisions\/1144"}],"wp:attachment":[{"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1111"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}