-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (28 loc) · 892 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
import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import cors from "cors";
import postsRoutes from "./routes/posts.js";
import userRoutes from "./routes/users.js";
import dotenv from "dotenv";
const app = express();
dotenv.config();
app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());
const port = process.env.PORT;
app.use("/api/posts", postsRoutes); // Meaning every routes in posts.js can only be accessed with /posts prefix
app.use("/api/user", userRoutes);
mongoose
.connect(process.env.CONNECTION_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
app.listen(port, () => {
console.log(`server running on port ${port}`);
});
})
.catch((error) => {
console.log(error.message);
});