when in the process of learning nuxt.js, so I’ve decided to create a small project with it. I read couple of documentation. There’s something that I did not fully understand though.
If Nuxt can use several backend framework (express, hapi, koa, others), can I use something like sequelize and create a fullstack app with it?
For example, I use express and sequelize to access a database. Then using nuxt’s asyncData to rendered it to my component without fetching using axios. Is it possible? Need some information about this
Solution :
Nuxt.js is backend agnosticmeaning you can use any backend technology to power the Nuxt.js (or Vue.js) application. In the case you can create the backend using express and sequelize. You cant directly access the database from the nuxt, you need to create interfaces that will provide data in the asyncdata.
<script>
import Customers from ‘~/plugins/Customers.js’
export default{
asyncData ({ params }) {
return Customers.getCustomers()
.then(result => { customers: result.users})
}
}
</script>
In the following example, getCustomers() returns a Promise which contains the users.
In the Customers.js you create an interfaces which will access the database. Hope this gives you an idea how you can implement, it is always recommended you abstract away the frontend and backend so that in future if you wish to change the backend stack the it will be easy to update, also making API requests to the express server in the asyndata would be good.