-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
52 lines (42 loc) · 1.43 KB
/
server.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
// Get dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const router = express.Router();
const mongoose=require('mongoose');
// Get our API routes
//const api = require('./server/routes/api');
const productmaster = require('./server/routes/productmaster');
const category = require('./server/routes/category');
const port = 5000;
const app = express();
// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));
mongoose.Promise = global.Promise;
var mongoURI = "mongodb://localhost:27017/pos";
// var MongoDB = mongoose.connect(mongoURI).connection;
// MongoDB.on('error', function(err) { console.log(err.message); });
// MongoDB.once('open', function() {
// console.log("mongodb connection open");
// });
mongoose.connect(mongoURI, { useMongoClient: true }, function (ignore, connection) {
connection.onOpen()
}).then(() => {
console.log('connected')
})
.catch(console.error)
// Parsers for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Set our api routes
//app.use('/api', api);
app.use('/api', productmaster);
app.use('/api', category);
// Catch all other routes and return the index file
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
app.listen(port,function(){
console.log("Server running on localhost:"+ port);
});