forked from lowsky/spotify-graphql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverInit.js
More file actions
executable file
·47 lines (40 loc) · 951 Bytes
/
serverInit.js
File metadata and controls
executable file
·47 lines (40 loc) · 951 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
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Module dependencies.
*/
var debug = require('debug')('spot-graphql-server:server');
var http = require('http');
require('dotenv/config');
const app = require('./app');
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '4000';
app.set('port', port);
/**
* Listen on provided port, on all network interfaces.
*/
app.on('error', onError);
app.listen(port, () => {
console.log(`listen on ${port}`);
});
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(`Port $port requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
console.error(`Port $port is already in use`);
process.exit(1);
break;
default:
throw error;
}
}