All Grains (Modules) used by Sand must first extend this base grain.
-
Install it:
$ npm install sand-grain -S
-
Create a new module which extends SandGrain and implement
SandGrain.nameproperty,SandGrain.init()method and, optionally,SandGrain.shutdown()var SandGrain = require('sand-grain'); var MyModule = SandGrain.extend({ name: 'MyModule', // required init: function(config, done) { // required this.super(config, done); // your initialization goes here }, shutdown: function(done) { // optional // implementing this hook is optional // your shutdown logic goes here // Make sure to call done when you are done shutting down } // add other public functions that you'd like to export here });
-
Use your shiny new module with Sand
var sand = require('sand')(); var MyModule = require('my-sand-module'); sand.use(MyModule).start(); // now that sand is started, you can use sand.MyModule.myFunction() anywhere in your project
ISC © 2014 Pocketly