-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (34 loc) · 1.09 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
import express from 'express';
import Razorpay from 'razorpay';
import dotenv from 'dotenv';
import { connectDB } from './DB/database.js';
import paymentRouter from './routes/paymentRouter.js';
//environment variables from .env file
dotenv.config();
const app = express();
// Initialize Razorpay instance
export const instance = new Razorpay({
key_id: process.env.RAZORPAY_API_KEY,
key_secret: process.env.RAZORPAY_API_SECRET,
});
// Middleware to parse JSON requests
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/api', paymentRouter);
const startServer = async () => {
try {
await connectDB();
console.log('MongoDB connected');
app.get('/', (req, res) => {
res.send('Server is running');
});
app.listen(process.env.PORT, () => {
console.log(`Server is running on port ${process.env.PORT}`);
});
} catch (error) {
console.error('Error starting the server:', error);
process.exit(1); // Exit process with failure code
}
};
startServer();
export default startServer;