-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathserver.js
43 lines (35 loc) · 1.11 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
// DEPENDENCIES
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
var mongoose = require('mongoose');
// c:\mongodb\server\3.0\bin\mongod.exe
// c:\mongodb\server\3.0\bin\mongo.ex
// Remember to connect to node server.js!
// CONTROLLERS
var SightingCtrl = require('./controllers/SightingCtrl'); // Don't need .js at the end
// SERVER VARIABLES
var app = express();
// EXPRESS MIDDLEWARE
app.use(bodyParser.json());
app.use(cors());
// ENDPOINTS
// TEST ENDPOINT
// app.get('/', function(req, res){
// res.send('hello');
// });
app.post('/sighting', SightingCtrl.create); // Referencing SightingCtrl.create in SightingCtrl.js
app.get('/sighting', SightingCtrl.read);
app.put('/sighting/:id', SightingCtrl.update);
app.delete('/sighting/:id', SightingCtrl.delete);
// CONNECTIONS
var port = 8980;
var mongoUri = 'mongodb://localhost:27017/mini-birds-mongoose';
mongoose.connect(mongoUri);
mongoose.connection.once('open', function(){
console.log('Connected to mongoDB at:', mongoUri);
});
// LISTENING
app.listen(port, function(){
console.log('Listening on port', port);
})