Saving Data Into MongoDB (with using mongoose) When HTML Button Clicked

I’m making a basic blog app and I want to save users’ data when they click submit button. I’m using mongoose for saving data in MongoDB. I wrote some code but it doesn’t worked. I’m new to this website things and I’m trying to learn.

There is code that I wrote for save into DB:

const mongoose = require("mongoose");
const User = require("../models/user");

const db_URI = 'my db_uri in here, idk about security so i didn't write it'; 
const button = document.getElementById("submit-btn");


button.onclick = function() {
    var user = new User( { # I made this variable for just test
        password: "123",
        email: ""

This code is for my front-end part:

<!DOCTYPE html>
        <title>SIGN UP HERE</title>


        <form method="POST">
                <label id="name-lbl">Name: </label>
                <input type="text" name="nick" placeholder="Your nickname here">
                <label>E-mail: </label>
                <input type="text" name="email" placeholder="Your email here">
                <label>Password: </label>
                <input type="password" name="pwd" placeholder="Your password here">
                <label>Confirm password: </label>
                <input type="password" name="pwd" placeholder="Confirm your password">
            <button type="submit" id="submit-btn">Submit</button>
        <script src="../database/db_processes.js"></script>


You are mixing up some things here. Your backend application (your first code snippet) should be running “server side” using Node. How are you running it now? Also the first code snippet would not have access to the frontend components, like buttons and divs.

What I would suggest is to go through this tutorial: to learn the basics of the architecture(Client-server architecture). In part 3 they go through how to connect with Mongoose.