3 ms·
Yeah! You can use dnode on the browser. You'd then be calling functions in your code, which would get executed on the server side. All transparently. No more ex
by pkrumins 15y ago
Yeah! You can use dnode on the browser. You'd then be calling functions in your code, which would get executed on the server side. All transparently. No more explicit ajax calls.
Just write a server.js:
var express = require('express');
var app = express.createServer();
app.use(express.static(__dirname));
app.listen(8080);
console.log('http://localhost:8080/');
// then just pass the server app handle to .listen()!
var dnode = require('dnode');
var server = dnode({
zing : function (n, cb) { cb(n * 100) }
});
server.listen(app);
And whip up an index.html:
<html>
<head>
<script src="/dnode.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
DNode.connect(function (remote) {
remote.zing(66, function (n) {
document.getElementById('result').innerHTML = n;
});
});
};
</script>
</head>
<body>
n = <span id="result">?</span>
</body>
</html>
Then just run the server.js:
$ node server.js
And navigate to http://localhost:8080 http://localhost:8080!
- jerf 15y ago"You'd then be calling functions in your code, which would get executed on the server side. All transparently." Transparent RPC is an anti-pattern, not a benefit. http://news.ycombinator.com/item?id=2318249 http://news.ycombinator.com/item?id=2318249