-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (33 loc) · 901 Bytes
/
index.js
File metadata and controls
39 lines (33 loc) · 901 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
34
35
36
37
38
39
import express from "express";
import mongoose from "mongoose";
import bodyParser from "body-parser";
import dotenv from "dotenv";
import route from './routes/noteRoutes.js'; // Import the routes
import cors from "cors";
dotenv.config();
const app = express();
app.get("/api", (req, res) => {
res.send("Hello World 1123");
});
app.use(
cors({
origin: "*",
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true,
optionsSuccessStatus: 204,
})
);
app.use(bodyParser.json());
const PORT = process.env.PORT || 500;
const MONGOURL = process.env.MONGO_URL;
// Use the note routes
app.use('/api', route);
// Connect to the MongoDB database
mongoose.connect(MONGOURL)
.then(() => {
console.log("Database connected successfully");
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
})
.catch((error) => console.log(error));