-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (33 loc) · 934 Bytes
/
index.js
File metadata and controls
39 lines (33 loc) · 934 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const express = require("express");
const mysql = require("mysql");
const bodyparser = require("body-parser");
const app = express();
app.set("view engine", "ejs");
app.use(bodyparser.urlencoded({ extended: true }));
app.use(express.static(__dirname + "/public"));
let port = 8080;
let connection = mysql.createConnection({
host: "localhost",
user: "root",
database: "join_us",
password: "Smriti@264",
});
app.get("/", (req, res) => {
let q = "SELECT COUNT(*) AS count FROM users";
connection.query(q, (err, results) => {
if (err) throw err;
var count = results[0].count;
res.render("home", { count });
});
});
app.post("/register", (req, res) => {
var q = "INSERT INTO users SET ?";
let person = { email: req.body.email };
connection.query(q, person, (err, result) => {
if (err) throw err;
res.redirect("/");
});
});
app.listen(port, () => {
console.log(`Listening on ${port}`);
});