-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
33 lines (25 loc) · 966 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
const express = require('express');
const cookieParser = require('cookie-parser');
const dotenv = require('dotenv');
const cors = require('cors');
dotenv.config();
const app = express();
const { connectToMongo } = require('./db/mongo.connection');
const port = process.env.PORT || 5000;
const authRouter = require('./routers/auth.router');
connectToMongo();
// Enable CORS for all incoming requests
app.use(cors());
// Ensure express.json() middleware is used before any router to parse JSON bodies
app.use(express.json());
app.use(express.urlencoded({ extended: true })); // Changed extended to true to support parsing of arrays and objects
app.use(cookieParser());
app.use("/api/auth", authRouter);
app.get('/', (req, res) => {
res.status(200).send({
message: 'Express js Backend API Starting Template Developed by Ravindra Valand'
});
});
app.listen(port, () => {
console.log(`Server is running on port http://localhost:${port}`);
});