forked from kaiosilveira/nodejs-layered-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (31 loc) · 991 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
32
33
34
35
36
import http from 'http';
import express from 'express';
import winston from 'winston';
import crypto from 'crypto-js';
import mongoose from 'mongoose';
import jwt from 'jsonwebtoken';
import { v4 as uuid } from 'uuid';
import { ExpressAppFactory } from './src/app.js';
const PORT = process.env.PORT;
const libs = { mongoose, express, winston, crypto, uuid, jwt };
const env = {
ENCRYPTION_KEY: process.env.ENCRYPTION_KEY,
DB_HOST: process.env.DB_HOST,
DB_NAME: process.env.DB_NAME,
DB_PROTOCOL: process.env.DB_PROTOCOL,
DB_PORT: process.env.DB_PORT,
JWT_SIGNING_KEY: process.env.JWT_SIGNING_KEY,
};
bootstrap();
async function bootstrap() {
const expressApp = await ExpressAppFactory.create({ libs, env });
http
.createServer(expressApp.instance)
.listen(PORT, () => console.log(`🚀 Server running at ${PORT}`));
const die = async () => {
await expressApp.destroy();
process.exit(0);
};
process.on('SIGINT', die);
process.on('SIGTERM', die);
}