Anger
1
Im making a website for minecraft bank, it would have an admin panel who would be able to manage a users insurance status and money status,
the index.js with ExpressJS has an sytrax error which i cant fix:
Full error:
/home/runner/SunshineBankMC-Contuined/index.js:55
);
SyntaxError: Unexpected end of input
nothing special is there only the app listen and then console log server is running on port ${port}
Hey @Anger welcome to the forums.
Can we have a link to the repl or the code?
Anger
3
Check your notifications, i have invited u to the project.
It is better if you share your code here since everybody can help you and it can help people in the future.
1 Like
Anger
5
i know but its an private project which i dont want to be openly accessable i just want help
Anger
6
this is the code, i have there the issue
const express = require('express');
const ejs = require('ejs');
const sqlite3 = require('sqlite3');
const app = express();
let db = new sqlite3.Database('db.db')
db.run('CREATE TABLE IF NOT EXISTS users(username VARCHAR(16) NOT NULL,balance INT NOT NULL,insurance_status BOOLEAN)');
app.use(express.static('views/public'))
app.use(express.urlencoded({
extended: true
}))
app.set('view engine','ejs');
app.get('/', (req, res) => {
res.render('index')
});
app.get('/register',(req,res) => {
res.render('register');
})
app.get('/profile',(req,res) => {
res.render('profile');
})
app.get('/faq', (req,res) => {
res.render('faq');
})
app.post('/register',(req,res) => {
const username = req.body.username;
const password = req.body.password;
let sql = `SELECT * FROM users WHERE username = '${username}'`;
db.get(sql, (err, row) => {
if (err) {
console.log(err);
} else if (row) {
res.redirect('/register');
} else {
bcrypt.hash(password, saltRounds, (err, hash) => {
if (err) {
console.log(err);
} else {
db.run(`INSERT INTO users VALUES ('${username}', '${hash}', 0, '${email}')`);
res.redirect('/profile');
}})};
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
}
);
It looks like the error is the closing line before app.listen
. The }})};
doesn’t seem to be matching the brackets of the previous route.
Try removing the semicolon and adding })});
at the end and maybe format your code.
app.post('/register',(req,res) => {
const username = req.body.username;
const password = req.body.password;
let sql = `SELECT * FROM users WHERE username = '${username}'`;
db.get(sql, (err, row) => {
if (err) {
console.log(err);
} else if (row) {
res.redirect('/register');
} else {
bcrypt.hash(password, saltRounds, (err, hash) => {
if (err) {
console.log(err);
} else {
db.run(`INSERT INTO users VALUES ('${username}', '${hash}', 0, '${email}')`);
res.redirect('/profile');
}
})
}
})
});
Anger
8
i have fixed it myself. it was just i needed to “const port”