-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
executable file
·39 lines (36 loc) · 997 Bytes
/
server.js
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
const app = require('./app')
const http = require('http')
const port = process.env.PORT || 8000
const server = http.createServer(app)
app.set('port', port)
function onError (error) {
if (error.syscall !== 'listen') {
throw error
}
const port = process.env.PORT
const bind = typeof port === 'string'
? `Pipe ${port}`
: `Port ${port}`
switch (error.code) {
case 'EACCES':
console.error(`${bind} correr en otro puerto, este puerto requiere permisos de root`)
process.exit(1)
case 'EADDRINUSE':
console.error(`${bind} el puerto ya esta en uso client`)
process.exit(1)
default:
throw error
}
}
function onListening () {
const addr = server.address()
const bind = typeof addr === 'string'
? `Pipe ${addr}`
: `Port ${addr.port}`
if (process.env.NODE_ENV !== 'testing') {
console.info(`server corriendo en ${bind}`)
}
}
server.on('error', onError)
server.on('listening', onListening)
server.listen(app.get('port'))