-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (44 loc) · 1.33 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
/**
* Created by mgarcia on 11/2/2015.
*/
'use strict';
var express = require('express');
var path = require('path');
var rootPath = path.normalize(__dirname);
var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
var app = express();
//var mongoClient = require('mongodb');
//var assert = require('assert');
//var mongoClient = require('mongodb').MongoClient, assert = require('assert;');
//var mongoClient = require('mongodb'), assert;
var mongoClient = require('mongodb')
var url = 'mongodb://localhost:27017/mydatabase';
app.use(express.static(rootPath + '/app'));
var portNumber = '8000';
/*
app.get('/', function(req, res){
res.sendfile(rootpath + 'app/index.html');
})
*/
app.get('/route1', function(req, res){
res.sendFile(rootPath + '/app/index.html');
});
//handle posting of data from the client
app.post('/orderPizza', jsonParser, function(req, res){
//Try out mongo db
mongoClient.connect(url, function(err, db){
//assert.equal(null, err);
if (err){
console.log('failed to connect to mongo');
}
else{
console.log('connected to mongo');
db.collection('pizza').insertOne(req.body);
}
db.close();
});
console.log(req.body);
});
app.listen(portNumber);
console.log('Listening on port ' + portNumber);