-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (29 loc) · 937 Bytes
/
index.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
const expressServer = require('./lib/expressServer');
const wsServer = require('./lib/wsServer');
const { config } = require('./lib/config');
const { PORT } = config;
const readline = require('readline');
wsServer.on('request', expressServer);
wsServer.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
console.log(`==================== Key Actions ====================`);
console.log('Press "d" to toggle debug mode');
console.log('Press "Ctrl + C" to exit');
console.log('====================================================\n');
});
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
const keyActions = {
d: () => {
config.changeDebugMode();
config.logEnvironmentVariables();
},
'\u0003': () => {
console.log('Exiting...');
process.exit();
},
};
process.stdin.on(
'keypress',
(str, key) => keyActions[key.sequence] && keyActions[key.sequence]()
);