I am trying to create a login page using html and node.js. I have been able to send stuff to the database using only node.js and postman but now I am trying to get it working with my html page. When trying to send stuff, I get sent back to index.html and a scripts.js error. The scripts.js error comes from the index.html page but it only happens when I get redirected. That error is not my problem though because I cant even get my db to update which is the biggest part I am trying to solve.
app.js
app.use('/public', express.static(path.join(__dirname, 'static')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'static', 'index.html'));
});
app.use(bodyParser.json());
const { urlencoded } = require('body-parser');
app.use(express.urlencoded({ extended: true }))
const authRoute = require('./routes/auth');
app.use('/api/user', authRoute);
app.use('/api/posts', postRoute);
I am using a routes folder where I contain the auth.js. auth.js also contains the methods I use to login in and registering a account
auth.js
const User = require('../models/User');
const { registerValidation, loginValidation } = require('../validation');
router.post('/register', async (req, res) => {...}
router.post('/login', async (req, res) => {...}
register.html
<form action="/" method="/api/user/register">
<input type="name" placeholder="Name" name="name" id="name" required>
<input type="text" placeholder="Email" name="email" id="email" required>
<input type="password" placeholder="Password" name="passwrd" id="password" required>
<!-- <input type="password2" placeholder="Repeat Password" name="psw-repeat" id="psw-repeat" required> -->
<!--<button type="submit" class="registerbtn">Register</button>-->
<input type="submit" value="Continue">
</form>
</div>
</div>
Using postman when I need to register a account I do
http://localhost:3000/api/user/register
{
"name": "POST MAN",
"email": "[email protected]",
"password": "123456"
}
Similar to login except I do /login and only use email and password. If I can get the register part working than I would be able to get the rest working as well.