-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.js
39 lines (34 loc) · 983 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
var express = require('express');
var mysql = require('mysql');
var bodyParser = require("body-parser");
var app = express();
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(__dirname + "/public"));
var connection = mysql.createConnection({
host : 'l',
user : '',
database : '',
password : ''
});
app.get("/", function(req, res){
// Find count of users in DB
var q = "SELECT COUNT(*) AS count FROM users";
connection.query(q, function(err, results){
if(err) throw err;
var count = results[0].count;
res.render("home", {count: count});
});
});
app.post("/register", function(req, res){
var person = {
email: req.body.email
};
connection.query('INSERT INTO users SET ?', person, function(err, result) {
if (err) throw err;
res.redirect("/");
});
});
app.listen(8080, function(){
console.log("Server running on 8080!");
});