0

I have been looking in various posts, but cant seem to find if its possible or not to actually run node/express server and the client server (react app) at the same time when we do serve -s on a built app?

I know there are many libraries which can run many commands in a sequence from the package, but that would be for dev environment. But since I have the server together with the actual app, the server of course does not start when I write serve -s. Just starts the app and thats all.

Is there a way to start both server and the app with serve -s? Or the only solution is to make server and the app as 2 separate projects and start them separatelly?

EDIT: Just to clarify, as I have noticed some people suggesting serving the page via express. I have the app for the raspberry pi project and I need the node server to control the raspberry gpio and shell commands.

AlwaysConfused
  • 729
  • 2
  • 12
  • 37
  • An option is server side rendering of the app. Assuming you've a build script for the app, build the app and serve the resulting html file on one of the node app's route. That way only one port is used which makes sense even for deploying. – kimobrian254 Dec 22 '20 at 12:01
  • I wouldn't run the two processes at the same time. Either split them into two (although then you need to add configuration for CORS, API location, etc.) or serve the static assets *from Express* (you can see the latter approach in a starter kit I put together: https://github.com/textbook/starter-kit/wiki/Architecture). – jonrsharpe Dec 22 '20 at 12:02
  • I updated the question for a better understanding of why I would like 2 separate servers running for the frond and back end – AlwaysConfused Dec 22 '20 at 13:03

1 Answers1

0

Serve's purpose is to

serve a static site, single page application or just a static file

You have an express backend, which is not static, use that express server to serve your react-app just like in the examples.

What are static files?

yi fan song
  • 407
  • 2
  • 10