title: Heroku deployed MERN app, shows only "Not Found"
body: <p>I've written a MERN app and it works locally and pushes to heroku but when I go to the heroku app link it says only "Not Found". I've checked my package.json build script and added express route to serve static files but I'm getting the same result. The client folder is inside the root/backend folder and is made with create-react-app. Here is my server.js:</p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  const mongoose = require('mongoose');
  const socketio = require('socket.io');
  require('dotenv').config();
  
  const jwt = require('jsonwebtoken');
  const bodyParser = require('body-parser');
  const cors = require('cors');
  const expressSession = require('express-session');
  
  const commentroutes = require('./routes/commentRoutes');
  const postRoutes = require('./routes/postRoutes');
  const userRoutes = require('./routes/userRoutes');
  const messageRoutes = require('./routes/messageRoutes');
  const searchRoutes = require('./routes/searchRoutes');
  const statusRoutes = require('./routes/statusRoutes');
  
  const User = require('./models/user');
  const PrivateMessage = require('./models/privateMessage');
  
  const app = express();
  
  app.use(cors());
  
  // parse application/x-www-form-urlencoded
  app.use(bodyParser.json());
  
  app.use(
    expressSession({
      secret: process.env.SECRET || 'local development secret',
      saveUninitialized: false,
      resave: false
    })
  );
  
  // ##### ROUTES #####
  app.use('/user', userRoutes);
  
  app.use('/post', postRoutes);
  
  app.use('/comment', commentroutes);
  
  app.use('/message', messageRoutes);
  
  app.use('/search', searchRoutes);
  
  app.use('/status', statusRoutes);
  
  let onlineUsers = {};
  
  if (process.env.NODE_ENV === 'production') {
    //set static folder
    app.use(express.static('client/build'));
  }
  app.get('*', (req, res) =&gt; {
    res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
  });
  
  mongoose
    .connect(process.env.MONGO_URI, { useNewUrlParser: true })
    .then(res =&gt; {
      const expressServer = app.listen(process.env.PORT || 8000);
      console.log('listening on port 8000');
  
      // BEGIN SOCKET IO:
      const io = socketio(expressServer);
      io.on('connection', socket =&gt; {
        console.log('online users: ', onlineUsers, 'new user: ', socket.id);
        const setUpCurrentChatUser = async () =&gt; {
          const token = socket.handshake.query.token;
          if (!token) {
            console.log('no token auth denied');
          } else {
            try {
              const decoded = jwt.verify(token, process.env.SECRET);
              // console.log('DECODED: ', decoded);
              let current_time = Date.now() / 1000;
              if (decoded.exp &lt; current_time) {
                console.log('expired');
  
                // token is expired, not authorized
              } else {
                let decodedUser = await User.findOne({
                  _id: decoded.tokenUser.userId
                });
                const currentUser = {
                  userId: decodedUser._id,
                  socketId: socket.id
                };
                onlineUsers = addUser(onlineUsers, currentUser);
  
                const currentUserFriendList = decodedUser.friendList;
  
                const modifiedFriendList = currentUserFriendList.map(friend =&gt; {
                  if (friend in onlineUsers) {
                    const newFriend = {
                      friendId: friend,
                      isOnline: true,
                      socketId: onlineUsers[friend].socketId
                    };
                    return newFriend;
                  } else if (!(friend in onlineUsers)) {
                    const newFriend = {
                      friendId: friend,
                      isOnline: false,
                      socketId: null
                    };
                    return newFriend;
                  }
                });
  
                socket.emit('friendList', modifiedFriendList);
              }
            } catch (error) {
              console.log('jwt error ');
            }
          }
        };
  
        setUpCurrentChatUser();
  
        const addUser = (userList, user) =&gt; {
          let newList = Object.assign({}, userList);
          newList[user.userId] = user;
          return newList;
        };
  
        socket.on('newPrivateMessageFromClient', async message =&gt; {
          console.log('newPrivateMessageFromClient: ', message);
  
          const friendId = message.currentFriend.friendId;
          const friendSocketId = onlineUsers[friendId].socketId;
  
          const newPrivateMessage = new PrivateMessage({
            sender: message.senderId,
            recipient: message.currentFriend.friendId,
            participants: [message.senderId, message.currentFriend.friendId],
            content: message.message
          });
          newPrivateMessage.save().then(result =&gt; {
            console.log('newPrivateMessage: ', result);
  
            //to friend
            io.to(`${friendSocketId}`).emit('privateMessageFromServer', result);
  
            //to sender
            const userSocketId = onlineUsers[message.senderId].socketId;
            console.log('USER SOCKET ID: ', userSocketId);
            io.to(`${userSocketId}`).emit('ownPrivateMessageFromServer', result);
          });
        });
  
        socket.on('updateFriendList', async friendList =&gt; {
          const modifiedFriendList = friendList.map(friend =&gt; {
            if (friend in onlineUsers) {
              const newFriend = {
                friendId: friend,
                isOnline: true,
                socketId: onlineUsers[friend].socketId
              };
              return newFriend;
            } else if (!(friend in onlineUsers)) {
              const newFriend = {
                friendId: friend,
                isOnline: false,
                socketId: null
              };
              return newFriend;
            }
          });
  
          socket.emit('friendList', modifiedFriendList);
        });
  
        socket.on('disconnect', async socketId =&gt; {
          try {
            const token = socket.handshake.query.token;
            const decoded = jwt.verify(token, 'speakfriendandenter');
            const userId = decoded.tokenUser.userId;
            console.log(
              'DISCONNECT, socket id: ',
              socketId,
              'decoded.tokenUser.userId: ',
              decoded.tokenUser.userId
            );
            delete onlineUsers[userId];
            console.log('updated online users after disconnect: ', onlineUsers);
          } catch (err) {
            console.log(err);
          }
        });
      });
    })
    .catch(err =&gt; console.log(err));
  
  </code></pre>
  
  <p>and here is the package.json in my backend folder/root folder:</p>
  
  <pre><code>{
    "name": "backend",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "client-install": "npm install --prefix client",
      "start": "node server.js",
      "server": "nodemon server.js",
      "client": "npm start --prefix client",
      "dev": "concurrently \"npm run server\" \"npm run client\"",
      "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client &amp;&amp; npm run build --prefix"
    },
    "engines": {
      "node": "10.15.3",
      "npm": "6.9.0"
    },
    "author": "Thomas",
    "license": "MIT",
    "dependencies": {
      "bcryptjs": "^2.4.3",
      "body-parser": "^1.19.0",
      "cors": "^2.8.5",
      "crypto": "^1.0.1",
      "dotenv": "^8.1.0",
      "express": "^4.17.1",
      "express-session": "^1.16.2",
      "express-validator": "^6.2.0",
      "gridfs-stream": "^1.1.1",
      "jsonwebtoken": "^8.5.1",
      "method-override": "^3.0.0",
      "mongoose": "^5.6.11",
      "multer": "^1.4.2",
      "multer-gridfs-storage": "^3.3.0",
      "node": "^12.9.0",
      "socket.io": "^2.3.0"
    },
    "devDependencies": {
      "concurrently": "^5.0.0",
      "nodemon": "^1.19.1"
    }
  }
  </code></pre>