-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (22 loc) · 801 Bytes
/
app.js
File metadata and controls
28 lines (22 loc) · 801 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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const cors = require("cors");
require("dotenv/config");
app.use(cors());
app.use(bodyParser.json()); //computer: bleep-bloop-bleep, body-parser: that's what she said
//technically, converting the data into suitable format to transfer
//Import routes
const postsRoute = require("./routes/posts");
app.use("/posts", postsRoute); //brings the posts here, reduce clusturing
//Middlewares
app.get("/", (req, res) => {
res.send("We are on home");
});
//Connecting to a database (MongoDB/Mongoose)
mongoose.connect(process.env.DB_CONNECTION, { useNewUrlParser: true }, () =>
console.log("connected to DB!")
);
//Start listening to a server
app.listen(3000);