Unable to capture data payload from POST request in ExpressJS

Hey there, I'm having an issue with my Express server. Everything seems to be working fine, but I'm not receiving data from the POST method. I have already installed and configured body-parser as well.

const express = require("express")
const app = express()
var bodyParser = require('body-parser')  
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.post("/signup", (req,res)=>{
    var data = req.body
    res.send(req.body)
})

Answer №1

If this code doesn't solve your problem, please share how you typically send a POST request in order to help troubleshoot.

const express = require("express")
const app = express()
const bodyParser = require('body-parser')

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.post("/signup", (req, res) => {
  var data = req.body
  console.log(data)
  res.send(req.body)
})

app.listen(3000)

On the front-end side:

axios.post('http://localhost:3000/signup', {
  firstName: 'Fred',
  lastName: 'Flintstone'
})
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

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

JavaScript constructor functions may trigger ReSharper warnings for naming convention

When it comes to JavaScript coding, I personally prefer using PascalCase for constructor functions and camelCase for other functions. It seems like my ReSharper settings are aligned with this convention. However, when I write code like the following: func ...

There was an error in Threejs' PropertyBinding as it attempted to parse the trackName ".bones[].position

Version: THREE.WebGLRenderer 91dev Struggling to achieve a basic chest opening animation using three.js. Unfortunately, encountering an error while trying to create an action. PropertyBinding: Unable to interpret trackName: .bones[].position Link to t ...

Node-powered Angular

Currently working on setting up client-side routing with AngularJS and Node. Ran into some issues along the way. EDIT After making changes to my code based on recommendations from @PareshGami, following https://github.com/scotch-io/starter-node-angular, I ...

What is the best way to link a dynamic property with a bootstrap popover within a nested v-for loop?

After spending several days searching for an example to guide me without success, I am turning to SO with my specific use case. I am currently working on a Bootstrap Vue layout where I need to load dates into 12 buttons corresponding to months and display ...

A step-by-step guide on transferring Data URI from canvas to Google Sheet using the fetch method

I am trying to send an image as base64 code to a Google sheet using fetch. However, I am encountering an error that says "data_sent is not defined" when I run my code. I need help identifying the problem and finding a solution to fix it. For reference, & ...

Display multiple selection using JavaScript based on the element ID

I have a task to display the selected id using JavaScript, but currently, only the first select id is shown. Here is my HTML and JavaScript code: <tr> <td> <select name="jens_id[]" id="jens_id" required="" > <option ></op ...

JavaScript does not function properly with dynamically loaded content

Trying to load the page content using the JQuery load() method. See below for the code snippet: $(window).ready(function() { $('#content').load('views/login.html'); }); .mdl-layout { align-items: center; justify-content: center ...

Tips for organizing an array to match another array?

Issue at hand: I am faced with a situation where I have an array of objects that need to be sorted in ASC DESC order based on one of the object keys. Following this, I also need to sort an array of strings in the same manner as the array of objects. For ex ...

Click the "Add to Cart" button to make a purchase

Recently, I've been working on modeling an add to cart feature using jQuery. However, I have encountered a small issue that I'm trying to troubleshoot. When I click the mybtn button, the model displays and functions correctly, but there seems to ...

What is preventing obj from being iterable?

When I try to compile this code, an error appears stating that the object is not iterable. Why is this happening? My goal is to determine the number of users currently online. let users = { Alan: { age: 27, online: false }, Jeff: { age ...

Tips for retaining a chosen selection in a dropdown box using AngularJS

How can I store the selected color value from a dropdown box into the $scope.color variable? Index.html: <label class="item item-select" name="selectName"> <span class="input-label">Choose your favorite color:</span> <select id="colo ...

Exploring ways to retrieve information stored in localStorage within an android mobile application

I am currently developing an Android App using phonegap. The app is a simple game that generates random numbers for math problems. If the user answers correctly, their score increases, but if they lose, their name and current score are saved in localStor ...

Developing a project using create-react-app and Express

I'm faced with a challenge of querying a database while using create-react-app. Unfortunately, the library I'm using pg-promise is not compatible with Webpack and requires a Node server to function properly. To address this issue, I decided to i ...

There seems to be an issue with the HighCharts chart export feature as it is not showing the Navigator graph

We are currently using HighCharts version 4.2.2 http://api.highcharts.com/highcharts/exporting While going through their exporting documentation, I made a decision to not utilize their default menu dropdown. Instead, I only needed access to the .exportCh ...

CRITICAL ERROR: CALL_AND_RETRY_LAST Memory allocation failed - JavaScript heap exhausted

I am experiencing issues when trying to search using npm: npm search material However, I keep getting this error message: npm WARN Building the local index for the first time, please be patient FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaSc ...

Utilize Vue.js to incorporate an external JavaScript file into your project

Currently, I am utilizing Vue.js 2.0 and facing an issue with referencing an external JavaScript file in my project. The index.html file contains the following script: <script type='text/javascript' src='https://d1bxh8uas1mnw7.cloudfro ...

Enhancing Functionality: JavaScript customization of jQuery (or any other object's) function

Within this jsfiddle, the author has created a test for a custom knockout binding. A key aspect of the test involves extending jQuery. My question pertains to lines 30. $.fn.on = function(event, callback) { where it appears that any existing definition o ...

Using Vue.js to send various data to child components through the router

I am facing a dilemma with the nested router setup in my Vue app. Here is a snippet from my router/index.js: { path: "/parent", name: "Parent", component: () => import(/* webpackChunkName: "parent" */ &qu ...

Converting JSON to a list using JavaScript

As a beginner in JavaScript, I apologize for asking possibly a redundant question. Can someone guide me on the most effective way to parse json? I am specifically interested in extracting a list of strings under the name Maktg: { "d":{ "res ...

Adjusting the duration of the carousel in Bootstrap 4.2

Is there a way to alter the transition or fade duration of a carousel in BS4.2 using scripts? According to the BS documentation: Adjusting transition duration To modify the transition duration of .carousel-item, you can utilize the $carousel-transition Sa ...