Answer the question
In order to leave comments, you need to log in
Can you help me deal with POST requests in Node JS?
Hello, I'm taking a Node JS course and I'm going crazy.
In general, I want to learn how to send data from the registration form, but I have some kind of jamb, after entering the data and clicking on the button, I get a page with the inscription: Cannot POST /routes/register.js
If anything, my structure looks something like this:
____________________________________
HTML (folder)
- register.html
- index.html
routes (folder)
- register.js
index.js (here I have all sorts of crap, connecting modules, routes and starting the server)
____________________________________
Here are the contents of these files:
CODE In register.html
<form action="../routes/register.js" method="POST">
<input type="text">
<input type="email">
<input type="password">
<button>Регистрация</button>
</form>
const express = require('express')
const path = require('path')
const router = express.Router()
router.get('/register', async (req, res) => {
res.sendFile(path.join(__dirname, '../HTML', 'register.html'))
})
router.post('/register', async (req, res) => {
req.session.isAuth = true // не понимаю, что это за строчка и для чего она нужна
res.redirect('/index')
})
module.exports = router
Answer the question
In order to leave comments, you need to log in
req.session.isAuth = true // I don't understand what this line is and what it is for
Cannot POST /routes/register.js
or write action="/register"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question