Express.js Failing to Send Response Following POST Request

This is the function I have on the back end using express:

// Function to register a new user
exports.register_user = function(req, res) {
    var portalID = req.body.portalID;
    var companyName = req.body.companyName;
    var password = req.body.password;
    var password2 = req.body.password2;

    var salt = bcrypt.genSaltSync(12);
    var hash = bcrypt.hashSync(password, salt);
    password = hash;

    var params = {
        TableName: "HouseAccounts",
        Item: {
            "portalID": portalID,
            "companyName": companyName,
            "points": 0,
            "password": password,
        }
    }
    res.sendStatus(200);
}

And this is the fetch function on the front end:

function register() {
  fetch("MyURL/register", {
    method: "POST",
    headers: {
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "portalID": document.getElementById("portal-id").value,
      "companyName": document.getElementById("company-name").value,
      "password": document.getElementById("password").value,
      "password2": document.getElementById("password2").value
    })
  }).then(function(response){console.log(response)});
}

While I can receive the JSON data sent through the POST request on the express side and process it, unfortunately, on the front end, I am not getting any response from the back end. The connection times out with a status of (failed) and an error message

Uncaught (in promise) TypeError: Failed to fetch
in console.

Answer №1

It turns out that the issue stemmed from my use of AWS Cloud9, where my Public IP changed whenever I restarted the instance. This caused the request to not reach the server side at all.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JasmineJS: manipulating the DOM to achieve the desired outcome

Currently, I am in the process of writing unit tests for a function that requires fetching values from the DOM for processing. getProducts: function() { //Creating query data var queryData = {}; var location = this.$('#location').val(); ...

When utilizing a Slick carousel with three slides and setting autoPlay to true, the slider-nav behaves as if there are five slides

I am currently using the Slick carousel plugin and I want to feature a display of 3 photos. The issue is that when I set slidesToShow=2, everything works perfectly fine, but when I try to set slidesToShow=3, which equals the total number of slides, the bot ...

Is there a way to verify the presence of data returned by an API?

I am trying to implement a system in my Index.vue where I need to check if my API request returns any data from the fetchData function. Once the data is fetched, I want to return either a boolean value or something else to my Index.vue. Additionally, I wou ...

What are the steps to perform a search using Node.js and MongoDB?

Displaying my 'usergroups' data: { "_id": { "$oid": "58f7537ec422895572e988a1" }, "name": "aaa", "groupname": "group north,group south", "mobilenumber": "0509867865", "userid": "6035555c16" } Here are the data f ...

Unable to adjust the height of an MP4 video to properly display within a Material Box in both landscape and portrait orientations

While I have been learning JavaScript React, I encountered an issue with positioning an MP4 movie. You can view the code in this Codesandbox If you check out the FileContentRenderer.jsx file, you will see that the html5-video is used for the MP4. The g ...

Is it possible to utilize axios in Vue while utilizing CORS in the API?

I am encountering an issue with making a GET request to a CORS enabled corona virus API using axios and Vue. I have no control over their server, and my Vue app was created with vue-cli. Interestingly, I am able to make two requests from different APIs - ...

The format of app.use(express.static('public')) is used in Express to serve static files from a folder named

In an express app, the line app.use(express.static('public')) is utilized to designate a folder for accessing static files. I'm confused about the syntax of passing express.static('public') as an argument to the app.use() function. ...

Exploring VueJs 3: Strategies for loading and implementing actions on a component before mounting

Briefly: Can a virtual node be created outside of the DOM to preload images, seek videos... without ever being mounted in the real DOM? Detailed version: I want to ensure that the next slide appears only when it is fully initialized for a slideshow in Vu ...

Checking the validity of a JSON file extension using regular expressions

Using EXTJS, I have created a file upload component for uploading files from computer. I need to restrict the uploads to JSON files only and want to display an error for any other file types. Currently, I am able to capture the filename of the imported fil ...

How to confirm the parent state in Angular's UI router?

In summary, I am seeking a function similar to state.is() that can verify a state with multiple child states from one of those child states? This is the structure I have: Parent 1 Child 1.1 Child 1.2 Child 1.3 Parent 2 Child 2.1 ...

Modify the variable for each VU in K6 (refresh token)

When I start my K6 test, I utilize my setup() function to obtain a token that will be used by every VU. I want each VU to have the same token, rather than generating individual tokens for each one. Although this works fine initially, the challenge arises ...

Node.js Express: Bizarre Symbols when downloading XLSX File Attachment

Utilizing the xlsx-populate module in conjunction with node.js, I am transmitting the workbook as a buffer according to their guidelines. When using Postman to access the API and retrieve the xlsx file as an attachment, the response contains strange charac ...

React approach for managing multiple combobox values

Currently, I'm working on a page where users can upload multiple files and then select the file type for each file from a dropdown menu before submitting. These 'reports' are the uploaded files that are displayed in rows, allowing users to c ...

Ways to incorporate sass:math into your vue.config.js file

While using vue-cli with Vue 2.6 and sass 1.49, I encountered errors in the console related to simple division calculations: Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0. I attempted to ...

Obtain a specific element in Puppeteer JS by utilizing the waitForSelector function to detect when its class name changes

I am faced with a situation where I need to wait for a specific element to change its classes dynamically. The challenge arises when utilizing the waitForSelector function, as it fails to work when no new element is added to the DOM. Instead, it is the &l ...

What's the best way to refactor the `await nextEvent(element, 'mousemove')` pattern in my code once it is no longer necessary?

Within my React component, the code includes the following: class MyComponent extends React.Component { // ... trackStats = false componentDidMount() { this.monitorActivity() } componentWillUnmount() { this.trackStat ...

Issue encountered when attempting to alter the action attribute of a form: receiving an error message stating 'undefined is not a function'

I am attempting to dynamically set the action attribute of a form based on the button clicked in order to navigate away from a page. Once the action is updated, the form should be submitted and the new action carried out. Below is my jQuery function: fun ...

Inserting line breaks in the data retrieved through AJAX

Utilizing ajax to transfer data from a sophisticated custom field wysiwyg editor. Within the markup provided, I am specifically addressing the div with the 'bio' class. However, upon receiving the data, it is consolidated into one large paragraph ...

Updating the parameters when clicking on each pagination button: A guide

Does anyone have advice on implementing pagination? I am currently working on loading a datatable with a few records initially. Once the page is loaded, I want to be able to click on pagination buttons like next or any pagination buttons to display a new s ...

Using jQuery to trigger alert only once variable has been updated

I have a question that may seem too basic, but I can't find the solution. How do I make sure that the variables are updated before triggering the alert? I've heard about using callbacks, but in this case, there are two functions and I'm not ...