-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (40 loc) · 1.08 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
var express=require('express');
var logger=require('morgan');
var bodyParser=require('body-parser');
var path=require('path')
console.log('hello');
//App Requirements
var app=express();
app.get('/', function(req, res) {
res.sendfile('homePage.html', { root: __dirname + "/views" } );
});
var port = normalizePort(process.env.PORT||3000);
app.set('port', port);
app.use(logger('dev'));
var server = require("http").createServer(app);
console.log('server Started')
//Body-Parser Setup
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
//Database
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/test');
//Static Directories
app.use(express.static(path.join(__dirname, 'views')));
app.listen(3000);
//API Routing
var api=require('./api');
app.use('/api', api);
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}