forked from greenpioneersolutions/meanstackjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.js
More file actions
51 lines (47 loc) · 1.58 KB
/
run.js
File metadata and controls
51 lines (47 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module.exports = run
var extend = require('xtend')
var minimist = require('minimist')
var Mean = require('./server.mean.js')
var SocketIO = require('./server.socketio.js')
var Livereload = require('./server.livereload.js')
var MongoExpress = require('./server.mongo_express.js')
var mail = require('./server/mail.js')
var environment = require('./server/environment.js').get()
var settings = require('./configs/settings.js').get()
var argv = minimist(process.argv.slice(2))
function run (ServerConstructor, cb) {
var server = new ServerConstructor(extend(argv), function (err) {
if (err) {
console.error('Error during ' + server.serverName + ' startup. Abort.')
console.error(err.stack)
process.exit(1)
}
if (cb && typeof cb === 'function')cb()
})
process.on('uncaughtException', function (err) {
console.error('[UNCAUGHT EXCEPTION]')
if (err.code === 'EACCES')console.log('Try Running in Sudo or Admin access')
if (err.code === 'EADDRINUSE')console.log('The Port is already occupied')
console.error(err.stack)
if (environment === 'development') {
console.error('[UNCAUGHT EXCEPTION] ' + err.message)
console.error(err.stack.toString())
process.exit(1)
} else {
var message = {}
message.to = settings.email.error
message.subject = '[UNCAUGHT EXCEPTION] ' + err.message
message.text = err.stack.toString()
mail.send(message, function (err) {
if (err) throw err
process.exit(1)
})
}
})
}
if (!module.parent) {
run(Mean)
run(SocketIO)
run(Livereload)
run(MongoExpress)
}