-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (33 loc) · 935 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
35
36
37
38
39
40
41
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cors = require('cors');
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.options("*", cors());
const userRoutes = require('./routes/userRoutes');
// Define the base API path
const api = '/api';
// Middleware
app.use(bodyParser.json());
// Use the user routes with the base API path
app.use(`${api}/user`, userRoutes);
// Database Connection
mongoose
.connect(process.env.CONNECTION_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true,
dbName: "test",
})
.then(() => {
console.log("Database Connection is ready...");
})
.catch((err) => {
console.error("Database Connection Error:", err);
});
// Start the server
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
});