generated from danicunhac/node-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
37 lines (31 loc) · 867 Bytes
/
index.ts
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
import 'dotenv/config';
import chalk from 'chalk';
import { app } from 'server';
let loadingInterval: NodeJS.Timeout | null = null;
export const startLoading = (message: string) => {
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
let i = 0;
process.stdout.write('\r');
loadingInterval = setInterval(() => {
process.stdout.write(`\r${chalk.magentaBright(frames[i])} ${message}`);
i = (i + 1) % frames.length;
}, 80);
};
export const stopLoading = () => {
if (loadingInterval) {
clearInterval(loadingInterval);
loadingInterval = null;
process.stdout.write('\r\n');
}
};
const start = async () => {
try {
await app.listen({ port: 3000 });
startLoading('Server running on :3000..');
} catch (err) {
stopLoading();
app.log.error(err);
process.exit(1);
}
};
start();