Create a database with express to connect it with ReactJS

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

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.


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?

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.

1 Like

MERN stack tutorial


Tutorial for express and mongo

1 Like

Thanks for all the links

Can’t i do something like this:slight_smile:

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.

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.

1 Like

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

1 Like

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: