|
4 | 4 | * Module dependencies. |
5 | 5 | */ |
6 | 6 |
|
7 | | -const app = require('../app') |
8 | | -const debug = require('debug')('express:server') |
9 | | -const http = require('http') |
| 7 | +const app = require('../app'); |
| 8 | +const debug = require('debug')('express:server'); |
| 9 | +const http = require('http'); |
10 | 10 |
|
11 | 11 | /** |
12 | 12 | * Get port from environment and store in Express. |
13 | 13 | */ |
14 | 14 |
|
15 | | -const port = normalizePort(process.env.PORT || '3000') |
16 | | -app.set('port', port) |
17 | | -console.log(`Your express app is running on http://localhost:${port}`) |
| 15 | +const port = normalizePort(process.env.PORT || '3001'); |
| 16 | +app.set('port', port); |
| 17 | +console.log(`Your express app is running on http://localhost:${port}`); |
18 | 18 |
|
19 | 19 | /** |
20 | 20 | * Create HTTP server. |
21 | 21 | */ |
22 | 22 |
|
23 | | -const server = http.createServer(app) |
| 23 | +const server = http.createServer(app); |
24 | 24 |
|
25 | 25 | /** |
26 | 26 | * Listen on provided port, on all network interfaces. |
27 | 27 | */ |
28 | 28 |
|
29 | | -server.listen(port) |
30 | | -server.on('error', onError) |
31 | | -server.on('listening', onListening) |
| 29 | +server.listen(port); |
| 30 | +server.on('error', onError); |
| 31 | +server.on('listening', onListening); |
32 | 32 |
|
33 | 33 | /** |
34 | 34 | * Normalize a port into a number, string, or false. |
35 | 35 | */ |
36 | 36 |
|
37 | 37 | function normalizePort(val) { |
38 | | - const port = parseInt(val, 10) |
| 38 | + const port = parseInt(val, 10); |
39 | 39 |
|
40 | | - if (isNaN(port)) { |
41 | | - // named pipe |
42 | | - return val |
43 | | - } |
| 40 | + if (isNaN(port)) { |
| 41 | + // named pipe |
| 42 | + return val; |
| 43 | + } |
44 | 44 |
|
45 | | - if (port >= 0) { |
46 | | - // port number |
47 | | - return port |
48 | | - } |
| 45 | + if (port >= 0) { |
| 46 | + // port number |
| 47 | + return port; |
| 48 | + } |
49 | 49 |
|
50 | | - return false |
| 50 | + return false; |
51 | 51 | } |
52 | 52 |
|
53 | 53 | /** |
54 | 54 | * Event listener for HTTP server "error" event. |
55 | 55 | */ |
56 | 56 |
|
57 | 57 | function onError(error) { |
58 | | - if (error.syscall !== 'listen') { |
59 | | - throw error |
60 | | - } |
61 | | - |
62 | | - const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port |
63 | | - |
64 | | - // handle specific listen errors with friendly messages |
65 | | - switch (error.code) { |
66 | | - case 'EACCES': |
67 | | - console.error(bind + ' requires elevated privileges') |
68 | | - process.exit(1) |
69 | | - break |
70 | | - case 'EADDRINUSE': |
71 | | - console.error(bind + ' is already in use') |
72 | | - process.exit(1) |
73 | | - break |
74 | | - default: |
75 | | - throw error |
76 | | - } |
| 58 | + if (error.syscall !== 'listen') { |
| 59 | + throw error; |
| 60 | + } |
| 61 | + |
| 62 | + const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; |
| 63 | + |
| 64 | + // handle specific listen errors with friendly messages |
| 65 | + switch (error.code) { |
| 66 | + case 'EACCES': |
| 67 | + console.error(bind + ' requires elevated privileges'); |
| 68 | + process.exit(1); |
| 69 | + break; |
| 70 | + case 'EADDRINUSE': |
| 71 | + console.error(bind + ' is already in use'); |
| 72 | + process.exit(1); |
| 73 | + break; |
| 74 | + default: |
| 75 | + throw error; |
| 76 | + } |
77 | 77 | } |
78 | 78 |
|
79 | 79 | /** |
80 | 80 | * Event listener for HTTP server "listening" event. |
81 | 81 | */ |
82 | 82 |
|
83 | 83 | function onListening() { |
84 | | - const addr = server.address() |
85 | | - const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port |
86 | | - debug('Listening on ' + bind) |
| 84 | + const addr = server.address(); |
| 85 | + const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; |
| 86 | + debug('Listening on ' + bind); |
87 | 87 | } |
0 commit comments