Created
August 26, 2015 22:44
-
-
Save shamasis/294098ee734f59e7e6b9 to your computer and use it in GitHub Desktop.
SailsJS bootstrap module to log package version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ServerStatsBootstrap.js | |
* Bootstrap module to log server version from package file | |
*/ | |
module.exports = function (done) { | |
require('fs').readFile('package.json', function (err, data) { | |
// exit if error in reading file | |
if (err) { | |
sails.log.error('Unable to read package. %s', err); | |
return done(); | |
} | |
// parse in try-block to avoid crash during parsing error | |
try { | |
// convert package file to JSON | |
data = JSON.parse(data); | |
} | |
catch (e) { // when parsing error, exit | |
sails.log.error('Unable to parse package. %s', e); | |
return done(); | |
} | |
// all ok, so log the package version | |
sails.log.info('server version: %s', data.version); | |
done(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment