-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (36 loc) · 1016 Bytes
/
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
'use strict';
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
//Include models
var AlarmModule = require('./models/Alarm/app');
AlarmModule.init();
// set the view engine to ejs
app.set('view engine', 'ejs');
//Set the port of the application
app.set('port', (process.env.PORT || 5000));
//Set the public folder
app.use(express.static(__dirname + '/public'));
//Set up the body parser for the RestfullApi
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: false
}));
//Homepage
app.get('/', function(req, res) {
res.render('pages/index',{
alarm: {
minutes: 59,
hour: 23
}
});
});
//RestfulAPI
app.get('/sound', function(req, res) {
AlarmModule.setNewAlarm({hour:16, minute:6});
res.end();
});
//Starting to listen...
app.listen(app.get('port'), function() {
console.log('Node app is running at localhost:' + app.get('port'));
});