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
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.