-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (42 loc) · 1.17 KB
/
Copy pathserver.js
File metadata and controls
51 lines (42 loc) · 1.17 KB
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
import express from "express";
const app = express();
import bcrypt from 'bcrypt';
import passport from "passport";
import initializePassport from './passport-config.js'
initializePassport(passport)
const users = [];
app.set('view-engine', 'ejs');
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.get('/', (req, res) => {
res.render('index.ejs', { name: 'Kunal' });
});
app.get('/login', (req, res) => {
res.render('login.ejs');
})
app.get('/register', (req, res) => {
res.render('register.ejs');
})
app.post('/register', async (req, res) => {
try {
console.log('reqBody', req.body)
const hashedPassword = await bcrypt.hash(req.body.password, 10);
console.log('hashedPassword', hashedPassword);
users.push({
id: Date.now().toString(),
name: req.body.name,
email: req.body.email,
password: hashedPassword
});
res.redirect('/login');
} catch {
res.redirect('/register');
}
console.log('users', users);
})
app.post('/login', (req, res) => {
console.log(req.body);
})
app.listen(3000, () => {
console.log('Hello Server')
})