Use io.js and Node.js with Homebrew at OS X

Install io.js and Node.js with homebrew is super easy:

brew install iojs node

But you make notice this message for io.js formula:

This formula is keg-only.
iojs conflicts with node (which is currently more established)

Because of io.js uses node for its binary’s name, so Homebrew won’t link io.js’s binary to /usr/local/bin, unless force to link with command brew link iojs --force. That means you can’t use io.js directly (e.g. node app.js). You have to use absolute path (e.g. /usr/local/Cellar/iojs/1.0.4/bin/node app.js), or use nvm:

nvm use 0.11
node -v # v0.11.15
nvm use iojs
node -v # v1.0.4

Although it can work, but you have to change asolute path after io.js updated, or nvm may be unavailable in some situations (e.g. needs source $NVM_PATH/ It’s inconvenience. So I created a shell script to help things easier:

#!/usr/bin/env sh

if [ -d "$(brew --prefix)/Cellar" ]; then
  node=`find /usr/local/Cellar -name node | grep iojs/.*/bin/node`
  if [ ! -z "$node" ]; then
    $node $@
    echo "io.js not installed"
  echo "Homebrew folder not found"

This script searches io.js’s binary in Homebrew’s Cellar folder, and run it with passed arguments. You can consider it is an alias of /usr/local/Cellar/iojs/1.0.4/bin/node, except it will maintain version for you.

All you need to do is put this script into your $PATH and make it executable. If you don’t know how to, here is a guide:

cd $HOME
touch .bash_profile # or .bashsrc, .zshrc, depends on your environment
echo 'export PATH="$HOME/.scripts:$PATH"' >> .bash_profile
mkdir .script && cd $_
touch iojs && chmod +x iojs
open -a "EDITOR" iojs

Replace EDITOR to your favorite editor, then copy and paste the shell script into the file, and save.

That’s all. You can now run io.js and Node.js like this:

node -v # v0.11.15
iojs -v # v1.0.4

node app_for_node.js

iojs app_for_iojs.js

Note that this script can’t handle multiple versions for now, so after io.js updated, remember to run brew cleanup.

The shell script is published on Gist.


Now read this

Node.js, Travis CI and Coveralls

在 GitHub 或 npm 社区混多了,你肯定见过这些图示: 这些图示是 提供的服务,当然,像 npm、build、coverage 这些是别的服务提供的: npm - build - coverage - 其中 build 的作用是在你有 push 或 pull request 的时候,会执行设置好的 build 脚本,并记录 build 的详细日志: 通过... Continue →