LoginSignup
13
13

More than 5 years have passed since last update.

nodebrewでio.jsを入れてみたメモ

Posted at

nvm派だったんですけど、nodebrewがio.js対応したという話を聞いたので触ってみました。

nodebrew

ピクセルグリッドの@hokacchaさんが作っているnode.jsのバージョン管理システムです。

インストール

$ curl -L git.io/nodebrew | perl - setup

パス設定 (.bashrc や .zshrcに記載)

export PATH=$HOME/.nodebrew/current/bin:$PATH

適用

$ source ~/.zshrc

nodebrewが使えるようになります

$ nodebrew help

node.jsのインストール

lastestで最新が入るのがいいですね。バージョンを指定しないでとりあえず最新を使いたいってときには便利そうです。

$ nodebrew install-binary latest
$ nodebrew use latest

iojsをインストールしてみる

https://iojs.org/

インストール

$ nodebrew install-binary io@v1.0.1
$ nodebrew use io@v1.0.1
$ nodebrew ls
io@v1.0.1

current: io@v1.0.1

確認

$ iojs -v
v1.0.1
$ which iojs
/Users/sugawara_nobisuke/.nodebrew/current/bin/iojs

io.jsを使ってみる

io.jsはNode.jsと互換性があるみたいなので、Node.jsのサイトのtcpサーバーを立てるサンプルを使ってみます。
http://nodejs.org/

app.js
var net = require('net');

var server = net.createServer(function (socket) {
  socket.write('Echo server\r\n');
  socket.pipe(socket);
});

server.listen(1337, '127.0.0.1');
$ iojs app

こんな感じでブラウザに表示されます。

Echo server
GET / HTTP/1.1
Host: localhost:1337
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: ja,en-US;q=0.8,en;q=0.6

普通に動きますね。

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13