A Typical Module Layout
package.json
{
"main": "index.js"
...
}
index.js
var lib = require('lib');
| object Put extends Controller { | |
| def index = DecodeProtobuf(classOf[MyProtobuf]) { stack :MyProtobuf => | |
| Action { | |
| // do something with stack | |
| } | |
| } | |
| } |
| java.io.FilterInputStream.read(FilterInputStream.java:116) | |
| java.nio.channels.Channels$ReadableByteChannelImpl.read(Channels.java:221) | |
| scalax.io.ResourceAdapting$ReadableChannelAdapter.read(ResourceAdapting.scala:75) | |
| scalax.io.support.FileUtils$.copy(FileUtils.scala:130) | |
| scalax.io.traversable.Sliceable.toArray(Sliceable.scala:75) | |
| scalax.io.traversable.ByteResourceTraversable$$anonfun$toArray$2.apply(ByteResourceTraversable.scala:50) | |
| scalax.io.traversable.ByteResourceTraversable$$anonfun$toArray$2.apply(ByteResourceTraversable.scala:50) | |
| scalax.io.CloseableIterator$.withIterator(CloseableIterator.scala:124) | |
| scalax.io.traversable.ByteResourceTraversable.toArray(ByteResourceTraversable.scala:50) | |
| scalax.io.Input$class.byteArray(Input.scala:81) |
| message Client { | |
| required string uuid = 5; | |
| optional string accountid = 1; | |
| optional string email = 2; | |
| optional string status = 3; | |
| optional AccessToken token = 4; | |
| required int64 amount = 6; | |
| } |
| everyauth.everymodule.submodule('c9') | |
| .get('callbackPath', | |
| 'the url that c9 returns') | |
| .step('findOrCreateUser') | |
| .accepts('req res next') | |
| .promises(null) | |
| .callbackPath('/auth/c9') | |
| .findOrCreateUser(function(req, res, next){ | |
| console.log("c9 Auth"); | |
| }) |
| var zmq = require('zmq') | |
| function sockit(name){ | |
| var sock = zmq.socket('req'); | |
| sock.connect('tcp://127.0.0.1:9000'); | |
| sock.on('message', function(res){ | |
| console.log("%s: %s",name,res.toString()) | |
| }); | |
| return sock; | |
| } |
| var axon = require('axon') | |
| var PORT1 = 8900; | |
| var PORT2 = 8901; | |
| var push1 = axon.socket('push') | |
| push1.bind(PORT1) | |
| var push2 = axon.socket('push') | |
| push2.bind(PORT2) |
| process.openStdin() | |
| process.stdin.setRawMode(true) | |
| process.stdin.on('data',function(key){ | |
| console.log(key.toString()) | |
| }) |
| // you can omit DI for _light_ dependencies | |
| var async = require('async'); | |
| module.exports.inject = function( dependencies ){ | |
| // no direct require of _heavy_ dependencies | |
| var mysql = dependencies.mysql; | |
| var redis = dependencies.redis; | |
| // do whatever |
A Typical Module Layout
package.json
{
"main": "index.js"
...
}
index.js
var lib = require('lib');
| function Database(mysql,config){ | |
| this.mysql = mysql; | |
| this.config = config; | |
| // setup mysql connection based on config | |
| } | |
| Database.prototype.get = function(){ | |
| // return an open mysql handle |