-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (22 loc) · 841 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
const express = require('express');
const mongoose = require('mongoose');
const Product = require('./Models/Products.model');
const productRoute = require('./Routes/Products.route');
require('dotenv').config();
const cors = require('cors');
const port = process.env.PORT || 3000;
const app = express();
app.use(cors());
mongoose.connect(process.env.MONGO_URL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log(`Connected to MongoDB!`,mongoose.connection.db.databaseName))
.catch(err => console.error('MongoDB connection error:', err));
app.use(express.json());
app.use(express.urlencoded({extended:fazlse}));
//Routes
app.get('/', function(req, res){
res.send('Server is Running')
})
app.use('/api/products', productRoute);
app.listen(port ,()=>{
console.log(`Server is Running on ${port}`)
});