Every time I would press submit on my login or registration page I’d get this error coming from one of the node_module files:
node_modulespg-protocoldistparser.js:136
return new messages_1.DatabaseError(‘received invalid response: ‘ + code.toString(16), length, ‘error’)
I’m assuming it’s comin from my server.js file: this is what I currently have:
const express = require('express')
const app = express()
const bcrypt = require('bcrypt')
const bodyParser = require('body-parser');
const knex = require('knex');
const db = knex({
client: 'pg',
connection: {
host: 'localhost',
user: 'root',
password: '#sql2024',
database: 'loginform',
port: 3306
}
})
app.use(bodyParser.json())
app.use(express.static(__dirname + '/public'))
app.use(express.urlencoded({ extended: false }))
app.set('view-engine', 'ejs');
app.get('/', (req, res) => {
res.render('index.ejs')
})
app.get('/homes', (req, res) => {
res.render('homepage.ejs')
})
app.get('/login', (req, res) => {
res.render('login.ejs')
})
app.post('/login', async (req, res) => {
const hashedpass = await bcrypt.hash(req.body.password, 10)
const { email } = req.body;
db.select('name', 'email', 'hashedpass')
.from('accountusers')
.where({
email: email,
password: hashedpass,
})
.then(data => {
if(data.length){
res.json(data[0])
} else{
res.json('email or password is incorrect')
}
})
})
app.get('/signup', (req, res) => {
res.render('signup.ejs')
})
app.post('/signup', async (req, res) => {
const { name, email, password } = req.body;
const hashedpass = await bcrypt.hash(password, 20)
db("accountusers").insert({
name: name,
email: email,
password: hashedpass,
})
.returning(["name", "email"])
.then(data => {
res.json(data[0])
})
})
app.listen(3000, (req, res) => {
console.log('listening on port 3000......');
})
for app.post I originally had login-user and signup-user but getting rid of it changed nothing so I changed how I connected to the database by using const db = mysql.createConnection({host…}) which also didn’t work.
Jaden George is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.