-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (23 loc) · 891 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
// This file is an Express Server //
const connectToMongo = require('./dataBase'); // -> it is a function
const express = require('express');
const path = require('path');
const app = express();
const port = 5000;
const cors = require('cors')
// if we want to use local API or call API from brwoser than this middalware is needed //
app.use(cors());
// request to connect with MongoDB //
connectToMongo();
// Middlware if we want to use "request body" //
app.use(express.json());
// index page for localhost:5000 //
app.get('/',(req,res)=>{
res.send(`<h1>Backend Server for inotebook </h1>`)
})
// sending to routes (avialable routes) //
app.use('/api/auth',require(path.join(__dirname,"./routes/auth")));
app.use('/api/notes',require(path.join(__dirname,"./routes/notes")));
app.listen(port, () => {
console.log(`iNoteBook Backend listening on port http://localhost:${port}`)
})