The postman does not retain any data

I am currently facing an issue where I am using Postman to enter a post into a MongoDB server, but the post returns empty. Even after checking my server, nothing has been entered and there are no errors displayed.

Here is the route file:

router.post('/', async (req,res) => {
const post = new customer({
    fullName: req.body.fullName,
    id: req.body.id
});
try{
    const savedCust = await customer.save();
    res.json(savedCust);
} catch (err) {
    res.json({message: err});
}
});

module.exports = router;

This is what I submitted on Postman:

{
    "fullName" : "Tim Scott",
    "id": 87438
}

However, the response that I received is as follows:

{
    "message": {}
}

Answer №1

An issue was encountered stating that the function customer.save() does not exist. This occurred within the try {...} block in your route file. The reason for this error is that the function is actually not defined. Instead, you should be using post.save():

// route file
const express = require('express');
const router = express.Router();
const customer = require('../models/customer');
router.post('/', async (req,res) => {
  const post = new customer({
    fullName: req.body.fullName,
    id: req.body.id
  });
  try {
    const savedCust = await post.save(); // replace this line
    res.json(savedCust);
  } catch (err) {
    res.json({message: err});
  }
});

module.exports = router;

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

Signing out in ExpressJS with the help of PassportJS and MongoStore

Currently utilizing PassportJS for authentication and MongoDB for session management. Within app.js: app.use(express.session({ store: new MongoStore({ db: mongoose.connection.db }) })); For logging out: app.get('/logout', func ...

Tips for triggering a click event on a DOM element using Angular 2

How can I automatically load a component upon loading? <app-main id="tasks" [(ngModel)]="tasks"></app-main> Here is the function call from JavaScript: public tasks; ngOnInit() { this.tasks.click(); } I have attempted using document.getE ...

Ways to prevent websites from switching to landscape mode

Is there a way to prevent landscape mode on my website and restrict users to portrait mode, especially for devices with screen widths below 777px? I have custom headers that take up fixed position space of around 100px on the screen. If it is possible to ...

Verifying that a parameter is sent to a function triggering an event in VueJS

One of the components in my codebase is designed to render buttons based on an array of objects as a prop. When these buttons are clicked, an object with specific values is passed to the event handler. Here's an example of how the object looks: { boxe ...

How to update the selected autocomplete item in Vue using programming techniques?

Although I am still learning Vue, consider the following scenario: <v-autocomplete v-model="defaultUser" :hint="`User: ${defaultUser.username}`" :items="users" :item-text="item =>`${item.firstName} - $ ...

Repetitive cycling through an array

My array consists of classes: const transferClasses = [ { id: "c5d91430-aaab-ed11-8daf-85953743f5cc", name: "Class1", isTransfer: false, children: [], }, { id: "775cb75d-aaab-ed11-8daf-85953743f5cc", ...

Developing web applications using a combination of PHP, MySQL, and

I am in need of creating an HTML form that functions as CRUD. This form should be able to record inputs such as "row_number", "channel_name", and "ip_address". It will store all the data in a MySQL table using the "ORDER BY row_number" function. The form i ...

Creating dynamically generated nested text inputs with individual v-model bindings upon the clicking of a button

As a newcomer to vuejs, I am attempting to create nested textboxes dynamically with the click of a button. For a clearer explanation, please refer to this jsfiddle link: https://jsfiddle.net/avi_02/qLqvbjvx/ Let's use an analogy to grasp the iss ...

Change JSON information into a collection of Java objects

My JSON data is structured like this: [ { "data": "data", "what": "what2", "when": 1392046352, "id": 13, "tags": "checkid:testcheckid, target:server.id.test, id:testid" }, { "data": "Test", "what": "Test", "when": 139535097 ...

How can a loading circle be displayed upon clicking a button on a PHP website using JavaScript?

As a newcomer to the world of JavaScript programming, I'm facing a challenge that seems deceptively simple. My goal is to display a loading circle when a user clicks on an upload button, trigger external PHP code for image processing, and then make th ...

Is it achievable to set a tab value for an HTML form element?

I'm wondering if it's possible to set a tab character as the value for an HTML dropdown list. Here is the code I currently have: <select id="delimiter-select" class="form-control form-control-sm csv-select"> <option value ...

Implementing automatic number increment in Vue.js forms

I have a field where I can enter numbers <input type="text" class="form-control" id="validationTooltip01" v-model="verse.number" required> After saving the number in the database, I would like it to automatically increment. For example: If I inpu ...

Error in Continuous Integration for Angular 4: Unable to access property 'x' of an undefined variable

i am trying to display some data on the form but encountering an error: TypeError: Cannot read property 'title' of undefined below is my component code : book:Book; getBook(){ var id = this.route.snapshot.params['id']; ...

If the checkbox is selected, include an anonymous email in the field and conceal the field

I am looking to enhance my Feedback form by providing users with the option to submit feedback anonymously. However, my CMS requires both Email and Name fields to be mandatory. To address this, I am considering adding a checkbox that, when selected, auto ...

problems with using array.concat()

I am attempting to reverse a stream of data using a recursive call to concatenate a return array. The instructions for this problem are as follows: The incoming data needs to be reversed in segments that are 8 bits long. This means that the order of thes ...

AWS Cognito - ECS Task Fails to Start

I'm facing an issue with using JavaScript to execute a task in ECS Fargate. AWS suggested utilizing Cognito Identity Credentials for this task. However, when I provide the IdentityPoolId as shown below: const aws = require("aws-sdk"); aws.co ...

When attempting to edit a user, the MERN CRUD functionality restricts the ability to modify input fields

Currently, I am working on a project using MERN stack and implementing CRUD functionality for user data. However, I have encountered an issue when it comes to updating a user's information. I retrieve the data from MongoDB so that the fields are pre-f ...

Understanding the concept of for loops in JavaScript and incorporating them in CSS styling

Hello there! I initially used this code to draw 12 lines, but now I am looking to incorporate a for loop and implement it in CSS. Can someone please guide me on how to proceed? <!DOCTYPE html> <html> <head> <style> #straigh ...

There seems to be a problem with the Chart property getter as it

I'm in the process of creating an object that corresponds to chartJS's line-chart model <line-chart :data="{'2017-05-13': 2, '2017-05-14': 5}"></line-chart> There is an API I utilize which returns a standard arra ...

Unable to detect JavaScript in Chrome Developer Tools

I am experiencing a strange issue where my JavaScript code is not showing in the sources window. When I include a debugger statement in my JS and then reload the page, it successfully breaks and I can view the JavaScript code. However, the tab is labeled ...