1

I'm currently making an application using ReactJS for the front-end and NodeJS for the backend, however, I'm confused regarding how to connect those two. I read about both, server-side rendering and client-side rendering. I followed this tutorial (https://www.fullstackreact.com/articles/using-create-react-app-with-a-server/ ) as to how to connect my ReactJS app, which I created using creat-react-app and my node backend, however, I read that the solution of adding "proxy": "http://localhost:8000" (or whatever port node runs on) to the package.json file is only suitable for development. Anyway, what I would like to know is: What is the best way of connecting ReactJS and Node.js if the user should be able to enter,delete or update data, which is saved to a database?

11
  • You can use express.js or egg.js for back-end. Commented Jan 9, 2018 at 9:55
  • @Cecil that's what I'm doing (I should've mentioned that) but my problem is that I don't really understand how I'm supposed to connect the front-end to the backend. I'm not sure the way I'm handling it right now is particularly suitable and how it is going to work once the application is in production Commented Jan 9, 2018 at 9:58
  • You will have to provide some kind of an api that your react app can post to and fetch data from. Most common is a so called REST api. This not special to react or node. Every client-server-application needs it. Commented Jan 9, 2018 at 10:04
  • Forget about server side rendering for the moment. It has nothing to do with connecting server and client. This is just a way to provide an initially rendered page to the client, e.g. to allow crawlers of search engines like google to analyse your page or to reduce initial loading times. It can not replace an api for communication. Commented Jan 9, 2018 at 10:09
  • @A.S.J The first method is that the back end provides only the data interface (API), the front end only render the page, and the back end data interface is invoked in the page. The second way is that you can also use the template engine to render the pages in express and egg. It is recommended to use the first method. Commented Jan 9, 2018 at 10:12

1 Answer 1

1

You should check out Nextjs. It is based on React and NodeJS.

I believe this is exactly what you are looking for. It is an easy-to-use framework that handles all the difficult stuff when it comes to server rendering while keeping the frontend async and dynamic. Besides that. When you get better using it, you can do in dept configuration to optimize to you need. Hope that helps.

Try out one of the examples on the git repository.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.