-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·62 lines (40 loc) · 1.22 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const express = require('express');
const morgan = require('morgan');
const app = express();
const port = 3000;
const mongoose = require('mongoose');
// download nhi karna para express ki dependency hai
const parser = require('body-parser');
// app.get('*',function(req,res,next){
// count++;
// next();
// })
mongoose.connect('mongodb://localhost:27017/codeasylums', { useNewUrlParser: true });
app.use(parser.json());
app.use(parser.urlencoded({ extended: true }));
let count = 0;
app.use(morgan('dev'));
app.use('*', function (req, res, next) {
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Headers', 'content-type');
next();
})
//roting
const users = require('./routes/users');
app.use('/users', users);
const products = require('./routes/products');
app.use('/products', products);
const orders = require('./routes/orders');
app.use('/orders', orders);
app.get('/', function (req, res) {
res.send("hello world!");
})
app.get('/test', function (req, res) {
res.send("testing").status(204);
})
app.get('/count', function (req, res, next) {
res.send(count.toString()).status(204);
})
app.listen(port, function () {
console.log(`server running on port ${port}`);
})