-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (30 loc) · 988 Bytes
/
index.js
File metadata and controls
34 lines (30 loc) · 988 Bytes
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
const debug = require('debug')('node-mqtt:index');
const serverPort = process.env.PORT || 3000;
const http = require('http');
const app = require('./server/express.js');
app.set('port', serverPort);
const httpServer = http.createServer(app);
const mosca = require('./server/mosca.js')(httpServer);
httpServer.on('error', (error) => {
if (error.syscall !== 'listen') {
throw error;
}
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(serverPort + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(serverPort + ' is already in use');
process.exit(1);
break;
default:
console.error(error);
throw error;
}
});
httpServer.on('listening', () => {
debug('http+app server is listening on port '+serverPort);
});
httpServer.listen(serverPort);