If you are a front-end developer that has dabbled a little bit in node and like it, you probably need to build a list of tools (npm modules etc) you can use in your day-to-day development.
Here’s a small list of things I find I often reuse in different projects.
anything in a require() is an npm module, installable via npm install name
Working with files
- require(‘fs’); – obvious but the default node fs is useful
- require(‘fs-extra’); – an extended file system util that lets you do a lot more, like make files and directories and make files in paths that don’t exist yet, work with JSON etc.
- require(‘watch’); – an awesome file system watch tool you can configure to fire events on file change, creation etc. with various patterns and callbacks.
Headless browsers and DOM
Being in node does not mean you cannot work on a DOM or on a DOM-like abstraction to either open HTML documents, parse them etc.
- require(‘jsdom’); – jsdom is great, if you can get it to work in a hurry. It is also slow and has a dependency list longer than the Nile (including contextify, which is hard to build on WIN32 due to node-gyp and python). But it lets you get a very reasonable DOM to work with, loaded with JavaScript etc.
- require(‘cheerio’); – a light pseudo-DOM implementation that can load a document and allow you to use a jQueryLite-like version to query and manipulate it. For those that have given up on jsdom.
- PhantomJS – An actual headless implementation of webkit. PhantomJS is very useful for testing and CI. Powers frameworks like CapserJS
Working with Class
Goes without saying but. It’s much nicer to use a more classical OOP interface in your nodejs modules.
- require(‘mootools’); – mootools-server, comes with Class (global) as well as the mixins Events, Options and some prototype enhancements to String etc. As you’d expect. No return value, just
require(‘mootools’)
then use as per client. - require(‘prime’); – Kamicane and MooTools’ next gen micro lib that does OOP style classes but is more lightweight. Don’t forget to also install Arian’s prime-utils for some sugar like supers, setOptions etc.
- require(‘primish’); – My own version of prime, which does a lot on top of prime to make it nicer and easier to use in the browser, as well as sugar around emitter, supers and options
Working with CLI
Working on build tools often requires you to do several things: process arguments and format stuff nicely.
- require(‘clintish’); – Clintish is a fork of
clint
– also by Kamicane, it’s a micro processor for arguments with events and parsers, helper syntax etc. Very nifty. - require(‘colors’); – a very clever implementation that prototypes the String native with some getters for default colour names. Allows you to do stuff like
console.log(“hello”.red + ” there”.blue);
, no return value – just require once.
In the next part, I will cover a lot of tools like growl notifiers, build tools / minifiers, linters, (trans)compilers, HTTP / socket servers, streaming and so forth.