Capitalization of modules in Node.js

Tradition in Node.js dictates you import core modules using this style:

1
2
var fs = require('fs');
fs.readFile(packageJSONPath, readOperationDidFinish);

I’ve adhered to that style for the most part, but it’s always rubbed me the wrong way.
As a core modules that points to a collection of static methods, capitalization is more appropriate.
1
2
var FS = require('fs');
FS.readFile(packageJSONPath, readOperationDidFinish);

Where the correct decision becomes most apparent is when using the path module:

1
2
3
var Path = require('path');
var join = Path.join;
var path = join(process.cwd(), 'package.json');

We used lowercase for local values, and using lowercase for the path module easily results in naming conflicts.


git pug

I am an idiot who subconciously likes pugs, so I often type git pug instead of git push or git pull. Is this truly a problem?
Note if I execute the following:

1
npm install pugme -g

Then place this in my ZSH aliases file:

1
2
3
4
5
6
7
git() {
if [[ $@ == "pug" ]]; then
command pugme
else
command git "$@"
fi
}

Which results in


Harmonious Node.js

Setting up NVM w/ ZSH

Execute the following

1
2
3
4
5
mkdir -p ~ZSH_CUSTOM/plugins
cd ~ZSH_CUSTOM/plugins
git clone git://github.com/rummik/nvm-zsh.git
cd nvm-zsh
git submodule update --init

Then edit the plugins array in your ~/.zshrc to include nvm-zsh so that it
looks somewhat like this: plugins=(nvm-zsh history-substring-search git osx ruby)

Installing a newer version of node

  • Run nvm ls-remote to determine the latest version of Node
  • Install it: nvm install v0.11.15
  • Run node --v8-options | grep harmony to determine which harmony features are supported
  • Start using harmony features by running your code with node --harmony foo.js

Gotchas w/ Arrow Functions in ES6/Harmony

Note that the following does not work:

1
2
3
4
5
6
7
8
9
function ES6Example(){}
ES6Example.prototype.foo = function(bar){
return ((baz) => {
this.bar = baz
})(bar)
}
var es6Example = new ES6Example
es6Example.foo('qux')
console.info(es6Example.bar) //undefined

But this does:
1
2
3
4
5
6
7
8
function ES6Example(){
this.foo = baz => {
this.bar = baz
}
}
var es6Example = new ES6Example
es6Example.foo('qux')
console.info(es6Example.bar) // 'qux'


Installing mpstat

I’m testing out Scout App for server monitoring. It requires something called mpstat and it apparently isn’t installed.
To get it, run apt-get install sysstat.