-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (33 loc) · 1.02 KB
/
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
const express=require('express');
const mongoose=require('mongoose');
const userRoute=require('./routes/userRoutes')
const cookieParser=require('cookie-parser')
const cors=require('cors')
const dotenv=require('dotenv');
const noteRouter = require('./routes/noteRoutes');
const ejs = require('ejs');
const bodyParser = require('body-parser');
const path = require('path');
const PORT=process.env.port || 5050
const app=express();
dotenv.config()
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors({credentials:true,origin: process.env.CROSS_ORIGIN_URL}))
app.use(express.json())
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/user',userRoute)
app.use('/note',noteRouter)
app.set('view engine', 'ejs');
app.get('/',(req,res)=>{
res.send("SnapNotes-Backend")
})
mongoose.connect(process.env.DATABASE_CONNECTION_STRING)
.then(()=>{
app.listen(PORT,()=>{
console.log("Server started and Connected To database")
})
})
.catch((error)=>{
console.log(error)
})