Create a database with express to connect it with ReactJS

Create a database with express to connect it with ReactJS
0.0 0

#1

Hi to all!
How can i create a database with express to connect it with my web app coded in ReactJS?


#2

If by database you mean SQL/NoSQL database, then roughly what you need:

  1. Install chosen database server
  2. Get database binding/driver library and import it in your node.js application
  3. Connect to database and fetch / insert / update data

Going further, if you need your ReactJS - client application - to fetch data and modify data in database, you can’t do this (technically you can, but you should not) directly. You need to provide API on your server (node.js) application to be used by your ReactJS application.

This is very general description of what you need to do and the reason for that is that any kind of details would require writing a whole tutorial. Therefore what you need to do is search for tutorials, most probably you would be interested in MERN (MongoDB, ExpressJS, ReactJS, node.js) stack.


#3

I’m actually a bit stuck on understanding this as well. Do you know any good tutorials that explain how to integrate React with an API?


#4

So much theory… Let’ talk practical… I am very interested in a guide how to create a database with expressjs or mysql and how to connect the server with reactjs web app.

Thank you and any help is appreciated.


#5

MERN stack tutorial


#6

Tutorial for express and mongo


#7

Thanks for all the links


#8

Can’t i do something like this:slight_smile:
https://stackoverflow.com/questions/41332643/sending-data-to-database-in-react-js-web-application?


#9

Since you backend and frontend are separate components you will need to make an ajax request to your server.
example: you have an express route - app.get("/post"), you will make an ajax request to that route to get that data.


#10

I suggest having Redux (or some other state management library) handle your requests. Yes, it will require juggling another library in your code, but the time you put into learning this will pay off in time saved debugging.


#11

Yes you can. If you want to use mysql use it. Mongo is just easier to use for beginners.


#12

I always found it the otherway around then again as a kid I did PHP/MySQL projects for fun so maybe that’s why MySQL makes more sense to me (now days I really dislike the stack and want it to go away as newer technologies do things better) but either way I’m happy to see you are enjoying Mongo :slight_smile: