0

I build a project with nodejs and react. I don't know if I must split in 2 servers, one for the react app and one for API in nodejs and the react app ask request at nodejs server.

Or I must group both in only one nodejs process ? What's the difference ? There are a better choice ?

4
  • 4
    React doesn't care what you use on the backend. It's just a view Commented Dec 7, 2017 at 15:53
  • 2
    Don't run the React development server in production! Build it, then serve the static files however you like. Commented Dec 7, 2017 at 15:53
  • It's really up to you, I don't think there is a canonical approach, or that one is better than the other. Commented Dec 7, 2017 at 15:58
  • @Jaxx The mono-server is generally used for its simplicity but when it comes to scaling your application you would rather scale differently your application back-end process from your static serving server. That's why it always end up separated. It will still works fine as a single server for application that's doesn't needs to scale tho. Commented Dec 7, 2017 at 16:29

1 Answer 1

2

It's up to you React when builded is just static files, don't get confused by the development server. I would recommend you for the beginning to put them in one node process. Just declare the folder of the static files like this:

app.use('/app', express.static(path.join(__dirname + '/dist/app')));

Also if you are using React Router you should add this as your last router

app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/src/index.html'));
});

You can check my template repo with webpack here

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.