login and Signup
This commit is contained in:
44
Vivian/server.js
Normal file
44
Vivian/server.js
Normal file
@ -0,0 +1,44 @@
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
const mysql = require('mysql');
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
const db = mysql.createConnection({
|
||||
host: 'localhost',
|
||||
user: 'root',
|
||||
password: 'your_mysql_password',
|
||||
database: 'your_database_name',
|
||||
});
|
||||
|
||||
db.connect(err => {
|
||||
if (err) {
|
||||
console.error('Error connecting to MySQL:', err);
|
||||
} else {
|
||||
console.log('Connected to MySQL');
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/signup', (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
|
||||
// Perform server-side validation if needed
|
||||
|
||||
const sql = 'INSERT INTO users (username, password) VALUES (?, ?)';
|
||||
db.query(sql, [username, password], (err, result) => {
|
||||
if (err) {
|
||||
console.error('Error executing SQL query:', err);
|
||||
res.status(500).json({ success: false, message: 'Internal Server Error' });
|
||||
} else {
|
||||
console.log('User signed up successfully');
|
||||
res.json({ success: true, message: 'User signed up successfully' });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is running on http://localhost:${port}`);
|
||||
});
|
Reference in New Issue
Block a user