-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (33 loc) · 943 Bytes
/
index.js
File metadata and controls
42 lines (33 loc) · 943 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
import * as dotenv from "dotenv";
dotenv.config();
import express from "express";
import morgan from "morgan";
import chalk from 'chalk';
import mongoose from "mongoose";
import userRouter from "./src/routers/user-router.js";
const app = express();
const PORT = process.env.PORT || 3000;
const MONGO_DB_URL = process.env.MONGO_DB_URL;
app.use(
morgan(":method :url :status :res[content-length] - :response-time ms")
);
app.use(express.json());
app.use(userRouter);
app.use((req, res) => {
res.status(404).send({ message: "404 not found" });
});
const start = async () => {
try {
mongoose.set("strictQuery", false);
mongoose.connect(MONGO_DB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
app.listen(PORT, () => {
console.log(chalk.whiteBright.bgGreen(`Render server cool started at ${PORT}`));
});
} catch (e) {
console.error(chalk.whiteBright.bgRed(e));
}
};
start();