-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
58 lines (46 loc) · 1.21 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const knex = require('knex');
const db = knex({
client: 'pg',
connection: {
host: '127.0.0.1',
user: 'postgres',
password: 'Vpn3579',
database: 'loginform'
}
})
const app = express();
let initialPath = path.join(__dirname, "public");
app.use(bodyParser.json());
app.use(express.static(initialPath));
app.get('/', (req, res) => {
res.sendFile(path.join(initialPath, "index.html"));
})
app.get('/login', (req, res) => {
res.sendFile(path.join(initialPath, "login.html"));
})
app.get('/register', (req, res) => {
res.sendFile(path.join(initialPath, "login.html"));
})
app.post('/register-user', (req, res) => {
const { name, email, password } = req.body;
db("users").insert({
name: name,
email: email,
password: password
})
.returning(["name","email"])
.then(data => {
res.json(data[0])
})
.catch(err => {
if(err.detail.includes('already exists')){
res.json('email already exists');
}
})
})
app.listen(3000, (req, res) => {
console.log('listening on port 3000....')
})