-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
60 lines (47 loc) · 1.74 KB
/
server.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
require("dotenv").config();
const app = express();
const PORT = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());
const recipesRouter = require("./routes/recipes");
app.use("/recipes", recipesRouter);
const authRoutes = require("./routes/auth");
app.use("/auth", authRoutes);
mongoose.connect("mongodb://localhost:27017/recipeDB", {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("Successfully connected to MongoDB"))
.catch((err) => console.error("MongoDB connection error:", err));
// const { MongoClient, ServerApiVersion } = require('mongodb');
// const uri = "mongodb+srv://<username>:<password>@recipe-sharing-platform.5qato.mongodb.net/?retryWrites=true&w=majority&appName=recipe-sharing-platform";
// // Create a MongoClient with a MongoClientOptions object to set the Stable API version
// const client = new MongoClient(uri, {
// serverApi: {
// version: ServerApiVersion.v1,
// strict: true,
// deprecationErrors: true,
// }
// });
// async function run() {
// try {
// // Connect the client to the server (optional starting in v4.7)
// await client.connect();
// // Send a ping to confirm a successful connection
// await client.db("admin").command({ ping: 1 });
// console.log("Pinged your deployment. You successfully connected to MongoDB!");
// } finally {
// // Ensures that the client will close when you finish/error
// await client.close();
// }
// }
// run().catch(console.dir);
app.get("/", (req, res) => {
res.send("Recipe Sharing Platform API");
});
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});