Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React.js with Node.js Rest API

Should I include my Reactjs app in the same application as my REST API?

I am new to Reactjs. I have built a few standalone Node REST APIs. I am building a React app, an Android app and an iOS app (so the REST API needs to service all three applications). I was wondering what convention dictates when building the Node API.

There are 2 options as I see it...

1) I could build one large application that encompasses the REST API and React App. This app would service all the API calls from the mobile apps and react/web app. It would also serve all the views aka HTML, CSS, etc..

OR

2) I could build two smaller apps. One would serve the React app with the view templates with a separate (lighter) Node server. The second app would not hold any views. It just work as a JSON API to serve all three apps.

like image 601
jhilliar Avatar asked Oct 29 '22 22:10

jhilliar


1 Answers

I would recommend going with an isomorphic application. Check out this boiler plate: react-redux-universal-hot-example.

In your project, you can have two ports running: one for rendering your react views (I prefer server side rendering to provide faster web rendering) and the other for apis and web sockets.

Your mobile apps can also use the api/ws server for RESTful services.

like image 75
jbpark Avatar answered Nov 11 '22 04:11

jbpark