-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (25 loc) · 672 Bytes
/
app.js
File metadata and controls
25 lines (25 loc) · 672 Bytes
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
/** app.js - Main node executable
*
*/
// Require paths
var express = require('express');
var path = require('path');
var mongoose = require('mongoose');
var app = express();
app.use(express.static(path.join(__dirname, 'public'))); // serve static
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
mongoose.connect('mongodb://localhost/web_db');
app.get('/', function (req, res) {
res.sendFile('public/index.html', {
root: __dirname
});
});
app.get('/api/db', function (req, res) {
console.log(req.body);
res.redirect('/');
});
app.get('/api/hello', function (req, res) {
res.send('Hello World!');
});