Consulting, training, products, professional services
contact@wearefractal.comOpen source is at github.com/wearefractal
npm shrinkwrap
ALWAYS BEFORE PUSHING TO PRODUCTION!
Simple answer: Use kappa
You can use git or HTTP URLS to install packages!
{
"name": "cool project",
"dependencies": {
"module1": "http://godaddy.com/secret/package.tar.gz",
"module2": "git@secretgit.godaddy.com:myteam/module2.git"
}
}
var bunyan = require('bunyan');
var elasticsearch = require('bunyan-elasticsearch');
var logger = bunyan.createLogger({
name: "My Application",
streams: [
{ stream: process.stdout },
{ stream: new Elasticsearch() }
],
serializers: bunyan.stdSerializers
});
logger.info('Starting application on port %d', app.get('port'));
var requestLogger = function (req, res, next) {
var start = new Date();
var end = res.end;
res.end = function (chunk, encoding) {
var responseTime = (new Date()).getTime() - start.getTime();
end.call(res, chunk, encoding);
var contentLength = parseInt(res.getHeader('Content-Length'), 10);
var data = {
res: res,
req: req,
responseTime: responseTime,
contentLength: isNaN(contentLength) ? 0 : contentLength
};
logger.info(data, '%s %s %d %dms - %d', data.req.method, data.req.url, data.res.statusCode, data.responseTime, data.contentLength);
};
next();
};
app.use(requestLogger);
var errorLogger = function (err, req, res, next) {
logger.error({ req: req, res: res, error: err }, err.stack);
next(err);
};
app.use(errorLogger);
app.use(function (req, res, next) {
var requestDomain = domain.create();
requestDomain.add(req);
requestDomain.add(res);
requestDomain.on('error', function (err) {
var data = { req: req, res: res, error: err };
logger.fatal(data, err.message);
});
next();
});
setInterval(function () {
var startTime = Date.now();
setImmediate(function () {
var data = process.memoryUsage();
data.uptime = process.uptime();
data.pid = process.pid;
data.tags = ['process-metrics'];
data.lag = Date.now()-startTime;
logger.info(data,
'process.pid: %d heapUsed: %d heapTotal: %d rss: %d uptime %d lag: %d',
data.pid,
data.heapUsed,
data.heapTotal,
data.rss,
data.uptime,
data.lag
);
});
}, 5000);
var cluster = require('cluster');
var os = require('os');
if (cluster.isMaster) {
var children = os.cpus().map(cluster.fork);
cluster.on('exit', function(worker) {
cluster.fork();
});
return;
}
var server = require('./your-server');