I am building an app consists of 2 different resources
Each on his own different repository on GitHub.
Usually I used to refer to the web “build” dir. from inside the server to serve it as a static dir. using a code like this
path.join(__dirname, '..', '..', 'build')
as in “Heroku” for example
Now. How can I do the same on digitalocean ? How can i refer to the “build” dir. inside the Web app resource from inside the server resource as i don’t know the dir. structure of the app ?
This is my typical response I get
{"statusCode":404,"message":"ENOENT: no such file or directory, stat '/workspace/build/index.html'"}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hi there,
In a DigitalOcean App Platform environment, each application component (like your Node.js server and React frontend) is deployed as a separate service container. Due to the isolated nature of these services, they do not share a filesystem.
This means you cannot directly reference the
build
directory of your React app from your Node.js server as you would in a single-repository setup like on Heroku.Here are a few approaches to handle this situation:
1. Serve the React App as a Static Site
Deploy your React application as a separate static site within the same DigitalOcean App Platform project. This can be done by:
npm run build
oryarn build
).example.com
for your frontend andapi.example.com
for your backend).2. Use DigitalOcean Spaces
If you prefer to serve the static files directly from your Node.js server:
3. Use Docker and Multi-Stage Builds
If you’re familiar with Docker, you can create a Dockerfile for your Node.js server that also builds your React application. This is a bit more complex but keeps everything in a single container:
npm run build
), and another stage set up your Node.js server.Example Dockerfile (for approach 3):
In your Node.js server, configure it to serve the files from the
/server/public
directory (or whatever directory you choose).Hope that this helps!
Best,
Bobby