-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (28 loc) · 700 Bytes
/
app.js
File metadata and controls
33 lines (28 loc) · 700 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
const express = require("express");
const mongoose = require("mongoose");
const blogRouter = require("./routes/BlogRoutes");
const app = express();
//middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/api/blogs", blogRouter);
//configure mongoose
mongoose.connect(
process.env.MONGODB_URI || "mongodb://localhost/CRUD",
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
(err) => {
if (err) {
console.log(err);
} else {
console.log("Connected to MongoDB");
}
}
);
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
module.exports = app;