-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 839 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
31
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
const mongoose = require("mongoose");
const env = require("dotenv").config();
// Import routes
const authRoutes = require("./routes/auth");
const postRoutes = require("./routes/posts");
// Connnect to Database using mongoose
mongoose.connect(process.env.MONGODB_URI, () => {
console.log("Connected to Db");
});
// MiddleWare to use json
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/app/user", authRoutes);
app.use("/api/posts", postRoutes);
// Index Route
app.get("/", (req, res) => {
res.send({
msg: "Hello there this app is working totally fine",
route: "/app/user/register",
});
});
app.listen(PORT, () => {
console.log(`Server is running on port http://localhost:${PORT}`);
});