Skip to content

Instantly share code, notes, and snippets.

View tommedema's full-sized avatar
🎯
Focusing

Tom Medema tommedema

🎯
Focusing
View GitHub Profile
#runs the working directory unit tests
test:
NODE_ENV=test \
mocha --ignore-leaks $(shell find ./test -name \*test.js)
#deploys working directory
deploy:
make test
make deploy-git
@tommedema
tommedema / fileIterator.js
Created May 13, 2012 10:27 — forked from Raynos/0usage.js
Iterate all the files
var fs = require("fs"),
path = require("path");
function iterateFiles(uri, callback, done, fileRegexp) {
var counter = 1
fs.readdir(uri, errorProxy(done, readFiles))
function readFiles(err, files) {
counter += files.length
files.forEach(isDirOrFile)
deploy:
status=$(git status --porcelain)
test "x$(status)" != "x"
var EventEmitter2 = require('eventemitter2').EventEmitter2,
should = require('should'),
request = require('request'),
config = require('../../src/config');
describe('server', function() {
var mediator,
port = config.server.port;
var EventEmitter2 = require('eventemitter2').EventEmitter2,
should = require('should');
describe('server', function() {
var mediator;
beforeEach(function() {
mediator = new EventEmitter2({
var mediator;
beforeEach(function() {
mediator = new EventEmitter2({wildcard: false});
require('../src/server/creator.js')(mediator);
require('../src/server/configurer.js')(mediator);
});
var mediator = new EventEmitter2({wildcard: false});
mediator.once('boot.ready', function() {
mediator.emit('server.created');
});
mediator.once('boot.ready', function() {
var EventEmitter2 = require('eventemitter2').EventEmitter2,
should = require('should');
describe('server', function() {
var mediator = new EventEmitter2({
wildcard: false
});
require('../../src/routines/server/creator')(mediator);
module.exports = function(mediator) {
mediator
.on('boot.init', function() {
console.log('boot init phase, outputting process information:');
console.log('process argv: %j', process.argv);
console.log('process execPath: %s', process.execPath);
console.log('process working dir: %s', process.cwd());
console.log('process gid: %d', process.getgid());
console.log('process uid: %d', process.getuid());

All application logic is defined using routines. Routines are loaded on runtime and are passed a global event emitter instance, called the mediator.

##Example The following describes an application example structure.

Application objective: create a http server and serve a RESTful API (serves current music stations and the current songs for each station).

###File tree

  • src/ (contains source files)
  • bootstrap.js (initializes the application and loads routines)