-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
53 lines (41 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
44
45
46
47
48
49
50
51
52
53
var express = require('express');
var app = express();
var morgan = require ('morgan');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var Melody = require('./models/melody.js')
app.use(morgan('combined'));
// serve static files from the public directory
app.use( express.static(__dirname+'/public'));
app.use(bodyParser());
mongoose.connect('mongodb://localhost/tunendrop', function(err) {
if (err) {
console.log(err);
} else {
console.log('connected the database');
}
}
);
// set up a default route
app.get('/', function(req,res){
res.sendFile(__dirname+'/public/index.html')
})
app.post('/new', function (req , res) {
var newMelody = new Melody();
newMelody.noteSequence = req.body.data1;
newMelody.save(function (err) {
if (err) {
throw err;
}
})
res.send(req.body)
})
app.get('/recentlycreated', function (req, res) {
Melody.find({}, function (err, melodies) {
res.send(melodies.slice(Math.max(melodies.length - 50, 1)))
})
})
// listen on a port
app.listen(3000, function(){
console.info('Listening on port 3000...')
})