DEV Community

Cover image for How To Connect Your Front-End Project To Back-End data/API.
Sharif Uddin Arnob
Sharif Uddin Arnob

Posted on

How To Connect Your Front-End Project To Back-End data/API.

If you are a developer with Node.js + Express and React & you are a beginner then this article gonna very useful for you.

Here i breakdown how to connect your front-end project to your back-end database. You can swap these for other tech stacks (Django, Flask, Laravel, Vue, Svelte, etc.) - concepts are the same.

1st step: Create your backend data/list. Always use JSON for data exchange unless you need files. Make sure you understand that where your back-end is set up, i prefer to do it with separate folder like (create-users-management-server), cause it will make our work organized.

2nd step: Test your back-end data by running it on server. In combination of node js and express, run (node server/index.js) or (nodemon). If all is Okay, your back-end setup is done.

3rd step: Now we will work on front-end code, when you fetch data, we might get an error, but no worry, it's for disabled CORS on the back-end, simply enable it by using this (app.use(cors()) ); Then you can see that the error is gone.

4th step: Yeah now you can get access data from your back-end, check your console.log, and you can easily update it on your UI for show to users.

Top comments (0)