Gaseous is a project mainly written in JavaScript, based on the View license.
Expose nodejs modules in the browser.
Expose nodejs modules in the browser.
Note: This is still a work in progress, use at your own risk, or see alternatives (like nowjs or dnode).
But... If you find this useful or cool, give it a spin or dive into the source.
npm install gaseous
// bind fs and initiate a server
var gaseous = require('gaseous');
gaseous.map({
fs: require('fs')
}).listen();
// with the cli
gaseous server -m fs
The client is used to connect and interact with a server instance.
For example: reading the contents of a file.
gaseous.connect(function (modules) {
// gaseous.modules can now be referenced
modules.fs.readFile("relative/directory/file", "utf-8", function (err, data) {
// woot
});
});
You have to build the browser client file to use it. First, make sure you:
// initialize submodules
git submodule init
git submodule update
// install some extra npm packages
npm install jake nodeunit sinon catchjs glob argsparser
// build the browser client
jake
jake build
// unit tests
jake test
// code stats
jake stats
// build the gaseous.js browser client and include it in your markup file
jake build
// or use the cli
gaseous build
// run the server example (or use the cli)
node example/server.js
// open example/client.html in a browser
chromium-browser example/client.html
The client/server runs on top of socket.io.
There is a caveat in that everything is async, so only certain methods are feasible. When a method call is made, the client will post the method and appropriate paramaters via a stringified data packet to the server. So if you want to use something like fs.readFileSync it will not work as expected.
For example, for fs.readFile the packet would look something like this:
{
"id": "uuid",
"method": "fs-readFile",
"args": [
"relative/directory/file",
"utf-8",
"[Function]"
]
}
The server will then process the packet, call the appropriate module method and a message will be sent back to the client with the results of the call.
For example, a successful call (to say fs.readFile) would look something like this:
{
"id": "uuid",
"callback": 2 // the index of the callback invoked
"args": [
null,
"file_data"
]
}