-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (26 loc) · 828 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
const express = require("express"),
mongoose = require("mongoose"),
morgan = require("morgan"),
app = express(),
port = 3900,
users = require("./routes/users"),
chalk = require("chalk"),
log = console.log,
error = chalk.bold.red,
success = chalk.bold.yellow,
auth = require("./routes/auth"),
cards = require("./routes/cards"),
cors = require("cors");
mongoose
.connect("mongodb://localhost:27017/rest_api")
.then(() => log(success("Connected to MongoDB...")))
.catch((err) => console.error(error(err)));
app.use(morgan(":method :url :status :response-time ms"));
app.use(cors());
app.use(express.json());
app.use("/api/users", users);
app.use("/api/auth", auth);
app.use("/api/cards", cards);
app.listen(port, () => {
console.info(success(`start server start listening on port ${port}`));
});