-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
85 lines (65 loc) · 2.13 KB
/
app.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// importing modules
var express = require('express');
var mongoose = require('mongoose');
var bodyparser = require('body-parser');
var cors = require('cors');
var path = require('path');
var app = express();
const sales = require('./routes/sales.js');
const creditsales = require('./routes/creditsales.js');
const cashPurchase = require('./routes/cashPurchase.js');
const creditPurchase = require('./routes/creditPurchase.js');
const expense = require('./routes/expense.js');
const employee = require('./routes/employee.js');
const payCreditPurchase = require('./routes/payCreditPurchase.js');
const addAccount = require('./routes/addAccount.js');
const addCompany = require('./routes/addCompany.js');
const journal = require('./routes/journal.js');
const close = require('./routes/close.js');
const paid = require('./routes/paid.js');
const register = require('./routes/register.js');
const productMaster = require('./routes/productMaster.js');
const categoryMaster = require('./routes/categoryMaster.js');
const login = require('./routes/login.js');
//connect to mongodb
mongoose.connect(process.env.MONGODB_URI || '',{useMongoClient: true});
//on connection
mongoose.connection.on('connected',()=>{
console.log('connected to database mongodb @ 27017');
});
mongoose.connection.on('error',(err)=>{
if(err){
console.log('error in connection databse'+err);
}
});
//port number
const port = process.env.PORT || 3000;
//add midleware
app.use(cors());
//body-parser
app.use(bodyparser.json());
//static file
app.use(express.static(path.join(__dirname,'public')));
app.use('/api', sales);
app.use('/api', cashPurchase);
app.use('/api', creditPurchase);
app.use('/api', expense);
app.use('/api', employee);
app.use('/api', creditsales);
app.use('/api', payCreditPurchase);
app.use('/api', addCompany);
app.use('/api', addAccount);
app.use('/api', journal);
app.use('/api', close);
app.use('/api', paid);
app.use('/api', register);
app.use('/api', login);
app.use('/api', productMaster);
app.use('/api', categoryMaster);
//testing server
app.get('/',(req, res)=>{
res.send('foobar');
});
app.listen(port,()=>{
console.log('server start at port:'+port);
});