Skip to content

Commit

Permalink
githubがおかしくなった?
Browse files Browse the repository at this point in the history
  • Loading branch information
omatoro authored and omatoro committed Jul 15, 2013
1 parent 788511b commit d783275
Show file tree
Hide file tree
Showing 132 changed files with 11,574 additions and 10,226 deletions.
20 changes: 10 additions & 10 deletions 001/001_helloworld.js
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,10 @@
/* /*
* hello, world * hello, world
* IPなど設定:http://testcording.com/?p=1164 * IPなど設定:http://testcording.com/?p=1164
*/ */


var http = require("http"); var http = require("http");
http.createServer(function (req, res) { http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});
res.end("hello, world!\n"); res.end("hello, world!\n");
}).listen(1337, "localhost"); }).listen(1337, "localhost");
13 changes: 13 additions & 0 deletions 002/002_起動したことが分かるようにする.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* hello, world
* IPなど設定:http://testcording.com/?p=1164
*/

var http = require("http");
http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"});
res.end("hello, world!\n");
}).listen(1337, "localhost", function () {
console.log("Server running at http://127.0.0.1:1337/");
console.log("サーバを終了する際は[ctrl + c]を押してください");
});
26 changes: 13 additions & 13 deletions 002/002_起動したことが分かるようにする.js
Original file line number Original file line Diff line number Diff line change
@@ -1,13 +1,13 @@
/* /*
* hello, world * hello, world
* IPなど設定:http://testcording.com/?p=1164 * IPなど設定:http://testcording.com/?p=1164
*/ */


var http = require("http"); var http = require("http");
http.createServer(function (req, res) { http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});
res.end("hello, world!\n"); res.end("hello, world!\n");
}).listen(1337, "localhost", function () { }).listen(1337, "localhost", function () {
console.log("Server running at http://127.0.0.1:1337/"); console.log("Server running at http://127.0.0.1:1337/");
console.log("サーバを終了する際は[ctrl + c]を押してください"); console.log("サーバを終了する際は[ctrl + c]を押してください");
}); });
16 changes: 16 additions & 0 deletions 003/003_IP_PORTをパラメータ化.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* hello, world
* IPなど設定:http://testcording.com/?p=1164
*/

var IP_ADDRESS = "localhost";
var PORT = 1337;

var http = require("http");
http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"});
res.end("hello, world!\n");
}).listen(PORT, IP_ADDRESS, function () {
console.log("Server running at http://" + IP_ADDRESS + ":" + PORT + "/");
console.log("サーバを終了する際は[ctrl + c]を押してください");
});
32 changes: 16 additions & 16 deletions 003/003_IP_PORTをパラメータ化.js
Original file line number Original file line Diff line number Diff line change
@@ -1,16 +1,16 @@
/* /*
* hello, world * hello, world
* IPなど設定:http://testcording.com/?p=1164 * IPなど設定:http://testcording.com/?p=1164
*/ */


var IP_ADDRESS = "localhost"; var IP_ADDRESS = "localhost";
var PORT = 1337; var PORT = 1337;


var http = require("http"); var http = require("http");
http.createServer(function (req, res) { http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});
res.end("hello, world!\n"); res.end("hello, world!\n");
}).listen(PORT, IP_ADDRESS, function () { }).listen(PORT, IP_ADDRESS, function () {
console.log("Server running at http://" + IP_ADDRESS + ":" + PORT + "/"); console.log("Server running at http://" + IP_ADDRESS + ":" + PORT + "/");
console.log("サーバを終了する際は[ctrl + c]を押してください"); console.log("サーバを終了する際は[ctrl + c]を押してください");
}); });
60 changes: 30 additions & 30 deletions 004/004_コメントをつける.js
Original file line number Original file line Diff line number Diff line change
@@ -1,30 +1,30 @@
/* /*
* hello, world * hello, world
* IPなど設定:http://testcording.com/?p=1164 * IPなど設定:http://testcording.com/?p=1164
*/ */
/* /*
* パラメータ * パラメータ
*/ */
var IP_ADDRESS = "localhost"; var IP_ADDRESS = "localhost";
var PORT = 1337; var PORT = 1337;


/* /*
* モジュール読み込み * モジュール読み込み
*/ */
var http = require("http"); var http = require("http");


/* /*
* サーバの作成 * サーバの作成
*/ */
http.createServer(function (req, res) { http.createServer(function (req, res) {
// ヘッダーの送信 送信するデータのタイプはtext/plain // ヘッダーの送信 送信するデータのタイプはtext/plain
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});
// 中身の文字列を送信 // 中身の文字列を送信
res.end("hello, world!\n"); res.end("hello, world!\n");
}).listen(PORT, IP_ADDRESS, function () { }).listen(PORT, IP_ADDRESS, function () {
/* /*
* サーバ起動時に表示するログ(起動したことが分かりやすい) * サーバ起動時に表示するログ(起動したことが分かりやすい)
*/ */
console.log("Server running at http://" + IP_ADDRESS + ":" + PORT + "/"); console.log("Server running at http://" + IP_ADDRESS + ":" + PORT + "/");
console.log("サーバを終了する際は[ctrl + c]を押してください"); console.log("サーバを終了する際は[ctrl + c]を押してください");
}); });
64 changes: 32 additions & 32 deletions 005/005_リクエストしたURLを表示する.js
Original file line number Original file line Diff line number Diff line change
@@ -1,32 +1,32 @@
/* /*
* hello, world * hello, world
* IPなど設定:http://testcording.com/?p=1164 * IPなど設定:http://testcording.com/?p=1164
*/ */
/* /*
* パラメータ * パラメータ
*/ */
var IP_ADDRESS = "localhost"; var IP_ADDRESS = "localhost";
var PORT = 1337; var PORT = 1337;


/* /*
* モジュール読み込み * モジュール読み込み
*/ */
var http = require("http"); var http = require("http");


/* /*
* サーバの作成 * サーバの作成
*/ */
http.createServer(function (req, res) { http.createServer(function (req, res) {
// リクエストされたURLをログに表示(ブラウザからアクセスされるたびにコンソールへ出力する) // リクエストされたURLをログに表示(ブラウザからアクセスされるたびにコンソールへ出力する)
console.log(req.url); console.log(req.url);
// ヘッダーの送信 送信するデータのタイプはtext/plain // ヘッダーの送信 送信するデータのタイプはtext/plain
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});
// 中身の文字列を送信 // 中身の文字列を送信
res.end("hello, world! : URL " + req.url); res.end("hello, world! : URL " + req.url);
}).listen(PORT, IP_ADDRESS, function () { }).listen(PORT, IP_ADDRESS, function () {
/* /*
* サーバ起動時に表示するログ(起動したことが分かりやすい) * サーバ起動時に表示するログ(起動したことが分かりやすい)
*/ */
console.log("Server running at http://" + IP_ADDRESS + ":" + PORT + "/"); console.log("Server running at http://" + IP_ADDRESS + ":" + PORT + "/");
console.log("サーバを終了する際は[ctrl + c]を押してください"); console.log("サーバを終了する際は[ctrl + c]を押してください");
}); });
33 changes: 33 additions & 0 deletions 006/006_非同期でファイル読み込み.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* hello, world
* IPなど設定:http://testcording.com/?p=1164
*/
/*
* パラメータ
*/
var IP_ADDRESS = "localhost";
var PORT = 1337;

/*
* モジュール読み込み
*/
var fs = require("fs");
var util = require('util');

/*
* 非同期でファイルを読み込む関数
*/
(function test() {
// 非同期でファイル読み込み(パスの指定は、nodeを起動しているパスからの相対パスになる)
fs.readFile("./testdata", "utf8", function (err, data) {
console.log("readFileを実行した!");
console.log(data); // 読み込んだファイルの内容を出力する
});
// 処理される順番が交錯するのに注目してください
console.log("readFile呼び出し終了");
// 以下の処理が終了した後、アイドル状態になってから上の非同期処理が行われる(キュー内の処理を順に呼び出すため)
// 一定時間サーバを酷使するのでテスト環境で実行してください
for(var i = 0, len = 10000; i < len; ++i) {
util.print(".");
}
})();
66 changes: 33 additions & 33 deletions 006/006_非同期でファイル読み込み.js
Original file line number Original file line Diff line number Diff line change
@@ -1,33 +1,33 @@
/* /*
* hello, world * hello, world
* IPなど設定:http://testcording.com/?p=1164 * IPなど設定:http://testcording.com/?p=1164
*/ */
/* /*
* パラメータ * パラメータ
*/ */
var IP_ADDRESS = "localhost"; var IP_ADDRESS = "localhost";
var PORT = 1337; var PORT = 1337;


/* /*
* モジュール読み込み * モジュール読み込み
*/ */
var fs = require("fs"); var fs = require("fs");
var util = require('util'); var util = require('util');


/* /*
* 非同期でファイルを読み込む関数 * 非同期でファイルを読み込む関数
*/ */
(function test() { (function test() {
// 非同期でファイル読み込み(パスの指定は、nodeを起動しているパスからの相対パスになる) // 非同期でファイル読み込み(パスの指定は、nodeを起動しているパスからの相対パスになる)
fs.readFile("./testdata", "utf8", function (err, data) { fs.readFile("./testdata", "utf8", function (err, data) {
console.log("readFileを実行した!"); console.log("readFileを実行した!");
console.log(data); // 読み込んだファイルの内容を出力する console.log(data); // 読み込んだファイルの内容を出力する
}); });
// 処理される順番が交錯するのに注目してください // 処理される順番が交錯するのに注目してください
console.log("readFile呼び出し終了"); console.log("readFile呼び出し終了");
// 以下の処理が終了した後、アイドル状態になってから上の非同期処理が行われる(キュー内の処理を順に呼び出すため) // 以下の処理が終了した後、アイドル状態になってから上の非同期処理が行われる(キュー内の処理を順に呼び出すため)
// 一定時間サーバを酷使するのでテスト環境で実行してください // 一定時間サーバを酷使するのでテスト環境で実行してください
for(var i = 0, len = 10000; i < len; ++i) { for(var i = 0, len = 10000; i < len; ++i) {
util.print("."); util.print(".");
} }
})(); })();
43 changes: 43 additions & 0 deletions 007/007_サーバ作成処理を分けて記述する.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* hello, world
* IPなど設定:http://testcording.com/?p=1164
*/
/*
* パラメータ
*/
var IP_ADDRESS = "localhost";
var PORT = 1337;
var startServer= function () {
/*
* サーバ起動時に表示するログ(起動したことが分かりやすい)
*/
console.log("Server running at http://" + IP_ADDRESS + ":" + PORT + "/");
console.log("サーバを終了する際は[ctrl + c]を押してください");
};

/*
* モジュール読み込み
*/
var http = require("http");

/*
* サーバの作成
*/
var server = http.createServer();

/*
* requestイベント受信時の処理(イベントハンドラ)を作成する
*/
server.on("request", function(req, res) {
// リクエストされたURLをログに表示(ブラウザからアクセスされるたびにコンソールへ出力する)
console.log(req.url);
// ヘッダーの送信 送信するデータのタイプはtext/plain
res.writeHead(200, {"Content-Type": "text/plain"});
// 中身の文字列を送信
res.end("hello, world! : URL " + req.url);
});

/*
* イベント待受状態を開始する
*/
server.listen(PORT, IP_ADDRESS, startServer);
Loading

0 comments on commit d783275

Please sign in to comment.