Appended data to formData in node.js…the data which i am posting to my api is always showing null?

Tags: , , , ,

Recently I was trying to append a lot of HTML form values to MongoDB database through an async process

this const createproperty are my MongoDB fields which i have taken in an array

 const createProperty =  ['propertyType',

.. these ids are some id’s from the HTML form which i have put in an array

const myids = ['#thisPropertyType',
            '#thisEp', ] 

this newproperty will give me the values from the Html form, all of the values are stored in the form of an array and this for loop works just fine which gives me all the form values perfectly

const newProperty = new Array();
    for(var i=0;i<myids.length;i++){
        newProperty[i] = $(myids[i]).val();

             const form = new FormData();
            for(var i=0;i<newProperty.length;i++){
            await createData(form);

this is the function which follows the async process

       export const createData = async (data) => {
    for (var value of data.values()) {
    const res = await axios({
        method: 'POST',
        url: '/api/v1/myapi',



i console.logged the values from the createdata function, it gives me the values perfectly but it is not pushing the values to the mongodb server, when i look at the collection, there is an document which is created but it has no data in it..

please help me where have i done wrong, i’m not getting where did i go wrong..

Thank you so much for helping me out!!


axios expect the data to be JSON object not FormData

This will construct the body as JSON with keys from createProperty array

const data = {};
myids.forEach((id, index) => {
    data[createProperty[index]] = $(myids[i]).val();

then you can send these values directly through axios

await createData(data)

Source: stackoverflow