This is a NodeJS module for WebKit. With this module, your Javascript code in HTML can call NodeJS functions directly. The following demo lists the current directory in the page:
<html><head>
<title>testfs</title>
<script>
var fs = require('fs');
function test_fs() {
var output = document.getElementById ('output');
output.innerHTML = '';
fs.readdir(".", function (err, files) {
var result = '';
files.forEach(function (filename) { result += filename + '<br/>'; } );
output.innerHTML = result;
});
}
</script></head>
<body onload="test_fs()">
<p id="output"></p>
</body>
</html>
From NodeJS code, you can manipulate DOM or run Javascript in DOM context as well:
var nwebkit;
nwebkit = require('nwebkit');
nwebkit.init ({'url' : "tests/testfs.html"},
function() {
nwebkit.context.runScript("document.body.style.background='#a3a3a3'");
});
A patched version of CEF(Chromium Embedded Framework) is need to make this possible. Prebuilt binaries are available for Linux (Debian and Ubuntu), Windows and OSX.
The source of Chromium is at https://github.com/rogerwang/chromium
Other hacks on the dependencies are:
https://github.com/rogerwang/node https://github.com/rogerwang/libuv
-
Chromium's (render process) main loop is merged with libev's main loop in NodeJS, so they can run in the same process.
-
WebKit is patched so the V8 context is merged (actually bridged) with the context from NodeJS. This makes NodeJS functions accessiable in web page.
Welcome to join the discussion in our mailing list:
http://groups.google.com/group/node-webkit
subscribe via node-webkit+subscribe@googlegroups.com
We believe that the async I/O framework in NodeJS and the Javascript programming language is a perfect combination for client (mobile) side applications. By bringing WebKit to NodeJS, a new way is avaliable to write applications with web technology. We'll contintue our development and support for this runtime. More platform and applications will be enabled.
MIT License