forked from gertie-sheshe/techinpink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (50 loc) · 1.49 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
(function() {
'use strict';
// Require dependencies that you will need. Dependencies perform a particular
// function in your application
// Express is a javascript routing framework.
var express = require('express'),
// Mongoose helps to connect to MongoDB
mongoose = require('mongoose'),
//Define the app
app = express(),
// Define your port
port = 3030 || process.env.PORT,
// Require the config file
config = require('./config/config'),
//Dependency to help with path
path = require('path'),
// Body Parser
bodyParser = require('body-parser'),
// Controller
Member = require('./server/controllers/member');
// routes
// routes = require('./server/routes/member');
app.use(bodyParser.json());
// Routes
app.get('/api/view', Member.find);
app.post('/api/save', Member.create);
app.delete('/api/delete/:email', Member.delete);
// Connect to the database
mongoose.connect(config.db, function(err) {
if (err) {
console.log('Could not connect to database');
} else {
console.log('Connected to database techinpink');
}
});
// Default path or route
app.get('/', function(req, res) {
// Deliver html file
res.sendFile(path.join(__dirname + '/public/index.html'));
app.use(express.static(__dirname + '/public'));
});
// Start up the server
app.listen(port, function(err) {
if (err) {
console.log('Cannot connect to port');
} else {
console.log('Connected on port ' + port);
}
});
})();