June 18, 2014

Installing Karma behind proxy


As part of working with AngularJS, I tried to install Karma test runner by using npm on one of our new Build Slaves. I got this error while executing the installation.
$ npm install karma

npm http 200 http://registry.npmjs.org/abbrev
> phantomjs@1.9.7-6 install /usr/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs
> node install.js
Downloading http://cdn.bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2
Saving to /usr/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/phantomjs/phantomjs-1.9.7-linux-x86_64.tar.bz2
Using proxy http://company-proxy.com:8080/
Receiving...
Error requesting archive.
Status: 403
Request options: {
  "protocol": "http:",
  "slashes": true,
  "auth": null,
  "host": "company-proxy.com:8080",
  "port": "8080",
  "hostname": "company-proxy.com",
  "hash": null,
  "search": null,
  "query": null,
  "pathname": "/",
  "path": "http://cdn.bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2",
  "href": "http://company-proxy.com:8080/",
  "headers": {
    "Host": "cdn.bitbucket.org",
    "User-Agent": "curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5"
  }
}
Response headers: {
  "cache-control": "no-cache",
  "pragma": "no-cache",
  "content-type": "text/html; charset=utf-8",
  "proxy-connection": "Keep-Alive",
  "connection": "Keep-Alive",
  "content-length": "606"
}
Make sure your network and proxy settings are correct.
npm ERR! phantomjs@1.9.7-6 install: `node install.js`
npm ERR! Exit status 1

Solution: Turns out that I need to set the proxy for npm:
$ npm config set proxy "http://company-proxy.com:8080"

Then I hit another problem, where the output has this error return code 407: Unauthorized; which means we need to add credential into the proxy config:
$ npm config set proxy "http://username:password@company-proxy.com:8080"
That's it. Installation is successful!

Side notes:

Sometimes, you might need to set the registry and set https-proxy:
npm config set registry http://registry.npmjs.org/
npm config set https-proxy https://username:password@proxy.company.com:8080

References:

June 8, 2014

Reasons I Start Blogging



So... I started blogging after many years. Well, better late than never. You might wonder what made me changed my mind.

For a start, I always wanted to document what I learned, problems I faced at work and their solutions. Normally I use Evernote, it is a great tool to keep notes; but it would be much better than I could share those notes with a wider developer community which I owe so much too. There are many times I found a solution to my current in someone's blog; so I hope I could return that favour, and someone would find my blog useful.

In this keynote Jackstones: the Journey to Mastery by Dan North, he mentioned a great way to learn is to teach. Blogging is a form of teaching, so by blogging I could reinforce what I learned.

I have been introduced to SEO (Search Engine Optimisation) in my work, and have learned the power of a good domain and content. That is an investment. An investment that grows with time.

Finally, this blog post really summarised it all, 15 reasons I think you should blog,  and made me push the "Start Blogging" button.

I sincerely hope you will find something valuable from my blog.  :-)