Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (44 sloc) 1.52 KB


Kyoshi is an abstraction on that allows Javascript in the browser to access files written for Node.js.

##How to use ###Setup

  require('kyoshi').listen(app, path);

Kyoshi attaches to your http object just like does. app is your http server. path is the path to your server-side javascript files. ###Server Side

  var userCount = 0;

  exports.users = function(callback) {
  exports.log = function(message) {
  exports.connect = function(id) {
  exports.disconnect = function(id) {

Any function exposed on the exports object is accessable to the client. The connect and disconnect functions are used by kyoshi to tell the file when someone connects and disconnects from the file. They both take an id. This is the unique id for the connection. ###Client Side

      <script src="/"></script>
      <script src="/kyoshi.js"></script>
      <script type="text/javascript">
        kyoshi('example.js', function(exports){
          exports.users(function(users) {
            console.log('There are '+users+' viewing this page!');
          exports.log('hello from connection ';

In this example, the page is referencing example.js from earlier. The client javascript is able to call any functions on the exports object built serverside.