node.js and native code extensions by example
DESCRIPTION
Over the last years node.js has evolved to be a great language to build web applications. The reason for this is not only that it is based on JavaScript which already is established around "the web" but also that it provides excellent facilities for extensions, not only via JavaScript but also integration of native C libraries. Couchbase makes a lot of use of this fact making the Couchbase node.js SDK (Couchnode) a wrapper around the C library providing a node.js like API, but leveraging the power of a native C library underneat. So how is this done? How does such a package look like? Let me show you how integration of C in node.js works and how to "read" a package like Couchnode.TRANSCRIPT
Node, native code and Couchnode
PHILIPP FEHRE
Twitter: @ischi
Github: @sideshowcoder
Developer Advocate, Couchbase
NODE.JS AND NATIVE CODE
Using C/C++ from node
Why would I want to do this?
Of course Speed!
Nope…
C is cool!
USING A C LIBRARY FROM NODE.JS
Probably the best reason
Couchnode is one of those cases
Based on libcouchbase + wrapper
Quick: What’s Couchbase?
A Document Database.
Focus on Performance
Allow flexibility by running JS
Using it from node.js
What happens here?
Seriously I like to show code
But this starts to be a little much
The hello world of extension
0.10 vs 0.11
Everything changes, welcome to the world of nan
What could go wrong?
Lets explore it by wrapping a C lib for murmur3 hashing
Wrapping C
Arguments and callbacks
Some more couchnode
To finish of…
What happens on a GET
Why is cas an Array?
Couchbase Server 3.0 Beta Bug Bash Download, Find, Report, Win
• DOWNLOAD Couchbase Server 3.0 Beta
• Run some workload, play with it, FIND a bug
• If you find a bug, REPORT it!
- All bugs count – anything from correctness, to performance, to usability, to docs
• WIN Prizes!!
http://www.couchbase.com/bugbash
Contest ends Aug 31st 2014
Come to spanconf.io
Thank you!
Any questions?
Links
• https://github.com/kkaefer/node-cpp-modules
• https://github.com/TooTallNate/node-gyp
• https://github.com/rvagg/nan
• https://github.com/couchbase/couchnode
• http://www.couchbase.com/communities/nodejs
• https://github.com/sideshowcoder/nurmur/