-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 805 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
32
33
34
//set up express js
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json()) //middle parsing json string to javascript object
require('dotenv').config();
//connectiong to mongodb
const mongoose = require('mongoose');
const uri = process.env.MONGODB_URI;
async function connect() {
try {
await mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true
});
console.log("Connected to MongoDB!");
} catch (error) {
console.error("Error connecting to MongoDB:", error);
}
}
connect();
const userRoutes = require('./routes/userRoutes');
app.use('/api/users', userRoutes)
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
})