-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
36 lines (31 loc) · 1.07 KB
/
app.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
import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import mongoose from 'mongoose';
import userRouter from './routes/userRoutes.js';
import productRouter from './routes/productRoutes.js';
import orderRouter from './routes/orderRoutes.js';
import fs from 'fs';
import Stripe from 'stripe';
dotenv.config();
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const username = 'akila_l';
const password = 'ZUUQsnjqABxzkWFv';
const cluster = 'caffconfclstr0.gbbqp';
const dbname = 'myFirstDatabase';
mongoose.connect(
`mongodb+srv://${username}:${password}@${cluster}.mongodb.net/${dbname}?retryWrites=true&w=majority`
);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error: '));
db.once('open', function () {
console.log('Connected successfully to mongoDB');
});
const stripe = new Stripe(process.env.STRIPE_PUBLIC_KEY);
app.use('/api/products', productRouter);
app.use('/api/users', userRouter);
app.use('/api/orders', orderRouter);
export default app;