-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·39 lines (31 loc) · 982 Bytes
/
server.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
#!/usr/bin/env nodejs
var express = require('express');
var mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: 'submitform',
password: 'submitauth',
database: 'emails'
});
connection.connect(function(error) {
if(!!error){
console.log('Error connecting to database');
}else {
console.log('Connected to database');
}
});
app.use('/', express.static('.'));
app.use(express.urlencoded());
app.post('/submit-email', (req,res) => {
var subemail = req.body.email;
var subcontent = req.body.message;
var sql = `INSERT INTO submittedemails ( id, email,content ) VALUES ( null, '${subemail.toString()}', '${subcontent.toString()}' );`
console.log(sql);
connection.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
res.send('message sent!');
});
});
app.listen(8083,'localhost');