-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (35 loc) · 1.1 KB
/
index.js
File metadata and controls
48 lines (35 loc) · 1.1 KB
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
45
46
var express = require('express');
var mongoose = require('mongoose');
var bodyparser = require('body-parser');
var cors = require('cors');
var app = express();
const add_route = require('./route/add');
const get_route = require('./route/get');
const delete_route = require('./route/delete')
// connect to mongodb
mongoose.connect('mongodb://localhost:27017/MSME');
// on connection
mongoose.connection.on('connected', () => {
console.log('mongoDB connected at port 27017')
})
// on connection error
mongoose.connection.on('error', () => {
console.log(err);
})
const PORT = 3000;
//adding middleware - cors
// req res exhange between 2 domains localhost 3000 and localhost 27017
// use cors before each request sent to the server
app.use(cors());
// body parser important for post requests
app.use(bodyparser.json());
// route ending with/ will be directed to route file
app.use('/add', add_route)
app.use('/get', get_route)
app.use('/delete', delete_route)
app.listen(PORT, () => {
console.log('Server has been started at port: ' + PORT);
})
app.get('/', (req, res) => {
res.send("test11")
})