Search code examples
c++node.jsv8

How does node.js/[my own library/plugin] run on v8?


Does it use any libraries like this:

http://code.google.com/p/v8-juice

http://ui.ajax.org/#o3

https://github.com/tsa/vu8

Or has it written its own libraries? If v8 is written for executing javascript, why do node.js libraries use C code? Just for the filesystem/event stuff? If so, why was that necessary, doesn't v8 need events and filesystem stuff itself?

If I want to work with a database that only supports a C api, how would I go about doing that? Right now I'd probably write a v8-juice plugin.


Solution

  • node.js includes its own embedded version of v8 (not sure if it is customized or not, but it could be).

    Javascript itself provides no interface to things like file system I/O, so that you as the embedder (in this case node) have to provide native code objects to expose that functionality. The browser does the same thing for DOM and network features, by the way.

    If I want to work with a database that only supports a C api, how would I go about doing that?

    You'd need a node.js extension for this (a native code plugin). If you are lucky, someone has already made on for your database system, if not, look at the source code for a similar extension as to how those are written. And here is an introduction article. You'd need to be familiar with writing a v8 extension, because that is what a node extension basically is.

    If you are talking to the database over a network connection, and feel like implementing the wire protocol yourself, you could also try to do that in pure Javascript, like someone did for MySQL.