DailyJS

DailyJS

The JavaScript blog.


Tagaddons
Featured

functional addons node apps modules express

Node Overflow: Countly, Prelude, fibonacci-async

Posted on .

You can send in your Node projects for review through our contact form or @dailyjs.

Countly

Countly

Countly (GitHub: Countly / countly-server, License: Countly Community Edition License) from the Countly team based in Turkey is a mobile analytics server that has SDKs for iOS and Android. The web interface and API are separated into two applications -- the front-end is built with Express, and the API is a lightweight server. MongoDB is used to store data and sessions. The Express application is a fairly straightforward monolithic implementation.

In terms of client-side code, the Express app uses ejs for templates, and jQuery UI.

The authors have included an installation script, bin/countly.install.sh, which helps get the server-side component up and running. If you want to try it out without installing it, there's a demo on count.ly.

Prelude.ls

Prelude.ls (GitHub: gkz / prelude-ls, License: MIT, npm: prelude-ls) by George Zahariev is a functional programming library written with LiveScript, which is a bit like a more functional CoffeeScript.

The author has provided examples of every single function the library provides in both JavaScript and LiveScript. All functions are curried, so supplying an incomplete list of arguments will return a partially applied function:

var takeFour = take(4);  
takeFour('hello there'); //=> 'hell'  

The API feels quite lightweight in places because certain functions accept objects where a function might be used in similar libraries:

reject([false, true], {a: 0, b: 1, c: 0});  
//=> {a: 0, c: 0}

The author has included tests written with LiveScript.

fibonacci-async

fibonacci-async (License: MIT, npm: fibonacci-async) by Enno Boland is a response to certain well-known blog posts berating Node's performance at potentially unfair benchmarks. It's an asynchronous C++ Fibonacci series generator, which strikes me as something potentially useful as an educational example for those interested in writing Node addons.

Featured

templating addons node modules

Node Roundup: Blade, HighKick, Spellcheck

Posted on .

You can send in your Node projects for review through our contact form or @dailyjs.

Blade

Blade (License, npm: blade) by Blake Miner is a Jade-inspired template compiler:

In Blade, there are no "mixins" or partial templates. There are only functions, and they work just like regular JavaScript functions that you've come to know and love.

It's based on PEG.js and UglifyJS. I think it's extremely interesting to see a Jade-like PEG (parsing expression grammar), which is in blade-grammer.pegjs.

The functions that Blade produces take a callback that gets an error and HTML, so in that sense the API feels idiomatic:

tmpl({  
    'nav': {
        'Home': '/',
        'About Us': '/about',
        'Contact': '/contact'
    }
}, function(err, html) {
    if(err) throw err;
    console.log(html);
});

The author has also included Express middleware, client-side support, and there are some simple unit tests as well.

HighKick

HighKick (npm: highkick) by Azer Koculu is a lightweight test runner. It'll take a module and execute any method that starts with test, which is more similar to the CommonJS Unit Testing specification than most of the popular Node test frameworks.

Functions can be run before and after each test, or the entire module. There's also an asynchronous mode for running tests asynchronously.

Azer has been using it to test his own modules, so you can check out some of his examples on GitHub.

Spellcheck

Spellcheck (License: MIT, npm: spellcheck) by Brian White is an asynchronous Hunspell addon. This is the same library that OpenOffice uses, as well as Chrome.

You'll need dictionaries and affix files to get it to work, and the author has provided a link to these at the OpenOffice Wiki, under Dictionaries.

Featured

tutorials addons node windows windows-and-node gyp

Windows and Node: Addons

Posted on .

In this article we're going to look at addons. If you're a Node developer working in Windows then this article should give you enough background to at least understand the basic issues surrounding addons, and install them using npm.

Addons are something Unix-based Node developers generally have little trouble with. However, the history of addon support in Windows has been a little bit turbulent. We've seen various solutions come and go -- most notably node-waf and Cygwin -- but the community has now settled on node-gyp by Nathan Rajlich.

Hint: Addons use C or C++ libraries. Node modules may include both addons and JavaScript code.

Isaac Schlueter summarised it in this comment:

Node-waf doesn't work on Windows. We're working on a solution that will make it easier to get a build toolchain in Windows based on node-gyp. Many packages will have to be updated to use this instead, so we're trying to make it as easy a transition as possible.

Installing a Module with Native Code

The fibers module uses node-gyp for building its native components. However, the module's author, Marcel Laverdet, has packaged it in an extremely effective way. Rather than force everybody to build the module, he's included binaries in the npm package. These are not present in the GitHub repository, but are available through npm. This includes both 32 and 64 bit versions.

node-fibers installation in Windows

Therefore, simply running npm install fibers should result in a working module in Windows. The compressed archive on npm actually includes Linux, Mac OS, and Windows binaries, for example: bin/win32-ia32/fibers.node.

Building a Module in Windows

As an exercise, let's build the fibers module. I picked this one because I already know it works -- although there are other modules built with node-gyp, they don't all build correctly in Windows yet.

Building the module requires a few dependencies:

  • A global installation of node-gyp
  • Python 2.7
  • Microsoft Visual Studio ("Express" is free)

Installing node-gyp

The node-gyp module is easy to install, but just make sure it's installed globally so it'll be in your %PATH%:

npm install -g node-gyp  

Installing Python

GYP, or Generate Your Projects, is a build system that uses Python. GypUserDocumentation covers the basics, but from our perspective we just need a working version of Python 2.7.x to use it.

I installed Python 2.7.3 using the MSI installer.

Installing Microsoft Visual Studio

Microsoft provides a free edition of Visual Studio called Visual Studio 2010 Express. I downloaded the ISO and extracted the ISO using 7-Zip. It's 694 MB, so you might want to brew a suitable hot drink while it's downloading.

Installing Visual C++

Fortunately, Microsoft provide this suite of tools and compilers for free with no user registration.

Running Microsoft's IDE

Building the Module

I downloaded the latest zip of node-fibers from GitHub, opened Command Prompt, changed directory to the path of the extracted zip, then ran the following:

set PATH=%PATH%;C:\Python27  
node-gyp configure  
node-gyp build  

Building the fibers module

Once that was done I ran npm test, and the tests all passed. I found it quite satisfying to see Microsoft's compiler actually build something, and although it's not necessary to build the fibers module this way, there are other modules out there that don't include binaries in npm.

Conclusion

Hopefully you now appreciate a little bit about how addons are built in Windows. Although previously the situation was confusing, the community is starting to convert modules to build with node-gyp.

I suspect there will be cases where native code can't be shipped as binaries due to licensing constraints, but it would be encouraging to see more addons include binaries for Windows.

Featured

firefox firebug addons

FireRainbow

Posted on .

FireRainbow is an add-on for Firefox and Firebug that adds themable syntax highlighting. It uses the
JavaScript library CodeMirror
to perform the highlighting, and has CSS themes. You can get the themes
off
firerainbow/themes on GitHub and paste them into the Colors tab within Firebug.

The performance is good, and it makes Firebug that little bit more
usable and customised.

Another useful Firebug plugin is
Eventbug. I also wrote a post about Eventbug.