'Nodejs: Why is the page reloading when I upload a JSON file?

When I am updating a .json file (fs module) in nodejs server, the webpage is getting reloaded.

Client-side:
when the button is clicked, info is transferred to the server for processing, this is done using socket.io

registerBtn.click(event => {
    event.preventDefault()

    if (regUsername.val().length <= 2 || regPasssword.val().length < 8) {
        _showLoginRegisterError('Fill in all fields as indicated', 'register')
    } else {
        let username = regUsername.val()
        let mail = registerMail.val()
        let password = regPasssword.val()
        socket.emit('register', { username, password, mail })
    }
})

Server-side:

socket.on('register', data => { // when users registers

//checking if all the details of the user are valid
        
                        if (!data[0]) socket.emit('sign-log-error', 'register', 'Invalid mail')
                        else {
                            const validation = {}
                            validation[mail] = [username, password, data[1]]
                            jdb.assignI('other', 'validating', validation) //-> this is reloading the webpage
                            socket.emit('otp-sent-verify', mail)
                        }
                    })
                }
                else socket.emit('sign-log-error', 'register', 'Invalid mail')

                // now if user is verified, then add user to db
            }
        }
    })
});

I am sending updating a .json file that stores name of the users that to be verified. But when I am updating the json file, the page is getting reloaded and is disturbing the process.

jdb.assignI() is a function that just assigns some dataa to JSON files



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source