How to set Build Command and Publish directory for MERN stack project?

I’m trying to deploy my MERN stack project. But I keep getting error.
My github repo for this project is like
— root

How can I deploy when its repo has two folder(client and server)?

And for client side, what should I input in ‘Build Command’ and ‘Publish directory’?
FYI, scripts in package.json in client side is:
“scripts”: {
“start”: “react-scripts start”,
“build”: “react-scripts build”,


and for server side, what ‘Build Command’ should be?
FYI, scripts in package.json in server side is:
“scripts”: {
“start”: “nodemon index.js”


The docs cover Monorepo support. The Root Directory field will help if you have separated code in their respective folders.

A common pattern would be to have the frontend React app as a Static Site, e.g. Deploy a Create React App Static Site

And the backend as a Web Service, but you would know best what you need to get your dependencies installed and app setup.


1 Like

Thank you! I made each repo for client and server.
I could deploy client side, but now I have problem with server side.
It said Serve running on port : 5000 but when I open , it says Cannot GET / .

My package.json for backend is as below:

  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "start": "nodemon index.js"
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.20.0",
    "cloudinary": "^1.32.0",
    "cors": "^2.8.5",
    "dotenv": "^16.0.2",
    "express": "^4.18.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^6.5.2",
    "multer": "^1.4.5-lts.1",
    "nodemon": "^2.0.19"

And I set
Build Command : npm install,
Start Command : node index.js

I googled but couldn’t find solutions…

The port is likely the issue. Use the PORT env var, like shown in our Express example:

const port = process.env.PORT || 5000;

and then use that const in the Express listen, e.g.

app.listen(port, () => console.log(`Example app listening on port ${port}!`));


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.