Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Last active October 19, 2015 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxriverlynn/633f18289a8749769ebb to your computer and use it in GitHub Desktop.
Save mxriverlynn/633f18289a8749769ebb to your computer and use it in GitHub Desktop.
cleaning up w/ nanit
var mongoose = require("mongoose");
var wascally = require("wascally");
var AWS = require("aws-sdk");
var some = require("some-thing");
var other = require("other-thing");
var more = require("more-things");
mongoose.connect(connStr, function(err)(
if (err) { throw err; }
wascally.configure(config).then(function(){
var credentials = new AWS.SharedIniFileCredentials();
AWS.config.credentials = credentials;
some.configure(whatever, function(err){
if (err) { throw err; }
other.setup(stuff, function(err){
if (err) { throw err; }
more.thingsHere(function(err){
if (err) { throw err; }
// ... ok. FINALLY done with all the configuration
// now start up the real application
startServer();
})
})
})
}).then(undefined, function(err){
setTimeout(function(){
throw err;
})
})
});
// file: initializers/aws.js
var AWS = require("aws-sdk");
module.exports = function(next){
var credentials = new AWS.SharedIniFileCredentials({
profile: "test-architecting-express"
});
AWS.config.credentials = credentials;
next();
};
// file: initializers/mongoose.js
var mongoose = require("mongoose");
module.exports = function(next){
mongoose.connect("mongodb://localhost/test", function(err){
if (err) { return next(err); }
next();
});
};
// file: initializers/rabbitmq.js
var wascally = require("wascally");
module.exports = function(next){
var config = {
// ...
};
wascally
.configure(config)
.then(function(){
next();
});
.then(undefined, function(err){
next(err);
})
};
// file: initializers/something.js
module.exports = function(next){
some.otherConfig();
next();
};
var nanit = require("nanit");
nanit.initialize(function(err){
if (err) { throw err; }
startServer();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment