Install Node.js di Mac

  1. Install Brew
    Ketikkan perintah berikut di terminal:
    $ ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
  2. Ketikkan perintah berikut di terminal:
    $ brew install node
  3. Lakukan ujicoba untuk memastikan Node.js sudah berjalan di komputer Anda
    $ nano hello_node.js
    atau
    $ vi hello_node.js
    Masukan skrip berikut ke dalam editor:
    var http = require('http');
    http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Sugeng Rawuh Node.js\n');
    }).listen(8124, "127.0.0.1");
    console.log('Server running at http://127.0.0.1:8124/');
  4. Simpan dan jalankan perintah berikut:
    $ node hello_node.js
  5. Akan ada informasi berikut:
    Server running at http://127.0.0.1:8124/
  6. Buka browser favorit Anda, kemudian masukkan akses url http://127.0.0.1:8124/
  7. Selesai :)

Sampai tahapan-tahapan di atas, Anda sudah berhasil meng-install node.js dengan menggunakan Brew tanpa npm.

Apa itu npm ?

npm is a NodeJS package manager. As its name would imply, you can use it to install node programs. Also, if you use it in development, it makes it easier to specify and link dependencies.

Untuk mengaktifkan npm, ikuti langkah-langkah berikut:

  1. Ketikkan perintah berikut di terminal Anda
    curl https://npmjs.org/install.sh | sh
  2. Kemudian ketikkan pula perintah berikut untuk mendaftarkan NODE_PATH ke Path Environment:
    export NODE_PATH=/usr/local/lib/node_modules
  3. Selesai. 
Blog comments powered by Disqus