I’d review the coding standards checked by JSLint or look at the author of NPM (Isaac Shlueter’s) coding standards.
You could also look at the style used by notable Node.JS coders:
- TJ Holowaychuk
- Isaac Shlueter
- Tim Caswell
- Jeremy Ashkenas
- Felix Geisendörfer
- Charlie Robbins
- Marak Squires
- Aaron Heckmann
- Guillermo Rauch
- Mikeal Rogers
- Ryan Dahl + you could look at the actual Node.JS codebase
I’ll throw mine in there for good measure 😉
Edit: Suggestions from @alienhard
- Google JavaScript style Guide
- Felix’s Node.js Style Guide
IMO there’s a few golden rules you should follow:
- Never use
withoreval - Use
===over== - Always declare your variables with
varin the appropriate scope – don’t fallback to the global scope - Wrap your app in a closure
(function(){})()if you plan on releasing code that runs server-side as well as in the browser - Callbacks should take
erras the first argument and if they themselves take a callback as an argument, it should be last, e.g.callback(err, param1, param2, callback)
Indentation, spacing between braces and keywords and semicolon placement are all a matter of preference.