Creating Crud in Nodejs Error in the post

Asked

Viewed 41 times

0

const users ={
  nome: String,
  idade: Number,
  saldo: Number,
  aposta: ()=>{return dados}
};
const dados = {
  gama: String,
  investimento: Number,
  lucro: Number,
  totalRetorno: (investimento, lucro) =>{let total = investimento+lucro; return totalRetorno}
};

I’m trying to create a user

server.post('/users', (require, response) => {
  const { name, idade, saldo, aposta, game, investimento, lucro} = require.body; 

  users.push(name, idade, saldo, aposta(game, investimento, lucro));

  console.log("Usuario criado")
  return response.json(users, dados);
});

I can’t create user I don’t know why. ERROR: Typeerror: users.push is not a Function

  • But what would it be users for you to be giving push?

  • 2

    .push()is an array method, users is an object.

1 answer

2


It wasn’t very clear, I believe that when you push it you don’t treat the data as an object, if you put it this way :

   users.push({name, idade, saldo, aposta(game, investimento, lucro)});

could solve this problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.