jhilliar
jhilliar

Reputation: 179

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.

Upvotes: 5

Views: 5631

Answers (2)

skirodge
skirodge

Reputation: 1100

I recommend building the single application for both the frontend and backend. Once scaling becomes an issue, then separating the two makes more sense because you'll want the frontend content served from a CDN.

But for something small, separating frontend and backend would require you to have to run two separate servers and deal with CORS: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Upvotes: 0

jbpark
jbpark

Reputation: 127

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.

Upvotes: 2

Related Questions