Node.js のインストールをしてみた[プログラミング]
(2017-03-30 15:47:12) by shinoda
ちょっと最近 JavaScript をきちんと勉強してみようと思っているので、その一環として「サーバーサイド JavaScript 環境」である Node.js をインストールしてみた。
まあ、Node.js で実行するプログラムはピュアな JavaScript ではないようだが(require で外部モジュールの読み込みが出来たり)。
追記されている「とりあえずサクッとnodejsをインストールの場合」のとおり、手っ取り早く yum にて
$ sudo yum -y install epel-release
$ sudo yum -y install nodejs
$ sudo yum -y install npm --enablerepo=epel
と行った。
早速、動作確認をしてみる。
上記ページに載っている参考プログラムをそのまま使わせてもらい、
$ cat > helloworld.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
^D
$ node helloworld.js
Server running at http://127.0.0.1:1337/
と作成したサーバプログラムを実行し、1337番ポートで http リクエストを待つ。
で、別の shell から wget でアクセスしてみる。
$ wget http://127.0.0.1:1337/
--2017-03-30 13:54:19-- http://127.0.0.1:1337/
Connecting to 127.0.0.1:1337... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: "index.html"
[ <=> ] 12 --.-K/s in 0s
2017-03-30 13:54:19 (1.18 MB/s) - "index.html" saved [12]
$ cat index.html
Hello World
ちゃんと、「Hello World」というコンテンツが取得できているね。
正しくインストールは出来たようだ。
コメント投稿
次の記事へ >
< 前の記事へ
TOPへ戻る
Powered by
MT4i 3.0.8