Nicole Satiembre
Nicole Satiembre

Reputation: 11

React to Mern stack

I initially created my e-commerce project with React. Later I realized I need mongodb and node for it. How can I integrate my React app to Node Js so it becomes a full stack app?

I want them to be in one folder.

Upvotes: 1

Views: 102

Answers (1)

Giovanni Georgo
Giovanni Georgo

Reputation: 62

Nodejs is your backend from where you just connect to MongoDB and then return the data to your frontend, and to do that you will need to create API's on the backend and call them from your frontend.

And to do that you can initialize your nodejs in the same folder as react but I would recommend having two folders like backend and the frontend. Start your node app on some port, connect the MongoDB (use env variables), and create routes that the front end would call to get the information or post some information to the database.

To Sum up:

  • Set up node js
  • create a mongodb cluster
  • connect the cluster to node
  • create APIS in node (get, post etc. requests)
  • call the backend API in front end (react) to access/manipulate the database information

That's it, hopefully, it helps.

Upvotes: 1

Related Questions