Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
405 Error on Fetch to send Data from front to back

I am working on a registration form in HTML. The form uses script to take the data entered by user, and turn it into JSON format so that my backend can process it. My text editor is Visual Studio Code and I am checking the functionality of my code with Five Server extension. When I run the code, I get a 405 (method not allowed) message whenever I try to submit data. I suspect that when I make the fetch call, I am not properly referencing the resource. Does my JavaScript file need to be in the same folder as my HTML file? Or is my issue something else?

 <script>
        const form = document.getElementById('createAccount')
        form.addEventListener('submit', registerUser)
        // Will send Data as JSON
        async function registerUser(event) {
            event.preventDefault()
            const firstName = document.getElementById('signupFname').value
            const lastName  = document.getElementById('signupLname').value
            const email     = document.getElementById('signupEmail').value
            const username  = document.getElementById('signupUsername').value
            const password  = document.getElementById('signupPword').value
            
            //Is this right?
            const result = await fetch('/signup', {
                method: 'POST',
                headers: {
                    'Content-Type':'application/json'
                },
                body: JSON.stringify({
                    firstName,
                    lastName,
                    email,
                    password,
                    username

                })
            }).then((res) => res.json())

            console.log(result)
        }
    </script>

Here is my Javascript

const express = require("express");
const router = express.Router();
const path = require('path');
router.use('/', express.static(path.join(__dirname, 'static')));

// mongodb user model
const User = require("./../models/users");

// Password handler
const bcrypt = require("bcryptjs");

// Signup
router.post("/signup", (req, res) => {
  let { fname, lname, username, password, email } = req.body;
  fname    = fname.trim();
  lname    = lname.trim();
  username = username.trim();
  password = password.trim();
  email    = email.trim();

  if()
// Trimmed code for sake of space
)};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!