Why do I get the error "[]" when submitting a form?


I am trying to create a simple form handler using express. I tried the code below for my form:

<!DOCTYPE html>
<html lang="pt-br">
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="./css/style.css" rel="stylesheet" type="text/css">
        <script src="./js/main.js"></script>
        <title>CAMPEONATO CHUTESAL</title>
        <div class="main-login">
            <div class="left-login">
                <h1>Faça login<br>E participe do nosso campeonato</h1>
                <img src="./img/soccer-animate.svg" class="left-login-image" alt="Futebol animado">
            <form action ='/users/login' method="post">
                <div class="right-login">
                    <div class="card-login">
                        <div class="textfield">
                            <label for="email">E-mail</label>
                            <input type="email" name="email" id="email" onchange="validateFields()" placeholder="E-mail">
                        <div class="textfield">
                            <label for="password">Senha</label>
                            <input type="password" name="password" id="password" onchange="validateFields()" placeholder="Senha">
                        <button class="btn-login" type="submit" id="login-button" disabled="true">Login</button>
                        <label for="register" class="label2">Não tem conta? crie uma agora!</label>
                        <button type="register" class="btn-register" id="login-button" onclick="register()">Registrar</button>

Here is my index.js

// config inicial
const express = require('express')
const mongoose = require('mongoose')
const app = express()
const path = require('path')
const bodyParser = require('body-parser')

// forma de ler JSON / middlewares
    extended: true,


app.use(express.static(path.join(__dirname, 'public')));

// rotas da API
const usersRoutes = require('./routes/usersRoutes')

app.use('/users', usersRoutes)

And here is my usersRoutes.js

const router = require('express').Router()
const Users = require('../models/Users')

// CREATE - Criacao de Dados
router.post('/register',  async (req, res) => {

    const User = await new Users({
        name : req.body.txtName,
        email: req.body.txtEmail,
        password: req.body.txtPassword

router.post('/login', async (req, res) => {

    const email = req.body.txtEmail;
    const password = req.body.txtPassword;

    const Find = await Users.find({ email, password })

  module.exports = router

I keep getting the error "[]" after submitting the form to login in the system. I’ve tried everything on the internet but the error remains, am I forgetting some function? What am I forgetting?


Your body params are named email and password.

router.post('/login', async (req, res) => {
    const { email, password } = req.body;

    const Find = await Users.find({ email, password })

Also, you should consider encrypting your password with a library like bcrypt.
Storing them in plain text is really bad from a security point of view.

Answered By – lpizzinidev

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published