Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!