Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

112
Visualizações
Resource response style in express js with API?

I'm a nob in expressjs and just using it so I have this response in my controller

....
res.json({
    'data': {
        'user': {
            'id': user.id,
            'name': user.name,
            'email': user.email,
        },
        'token': token
    }
});

In Laravel, there is something called eloquent-resources that takes the data of something and puts it in a separate class, and arranges this data as you need!

IS there any thing like this in express js

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Eloquent is ORM for just Laravel. This is strongly connected with your application. There are many ORMs for express.js but most known is sequelize. It supports MySQL, PostgreSQL etc. It does have Model structure and you can use sequelize models for your responses.

    const User = sequelize.define('User', {
  // Model attributes are defined here
  firstName: {
    type: DataTypes.STRING,
    allowNull: false
  },
  lastName: {
    type: DataTypes.STRING
    // allowNull defaults to true
  }
}, {
  // Other model options go here
});

Like this and after that you can use your Model like a normal object and return it inside your response.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda