-1

I am not able to deploy my full stack application.

My repository looks exactly like this in terms of folder structure:

The following is my package.json:https://github.com/bradtraversy/mern_shopping_list

{
  "name": "clear",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start:prod": "NODE_ENV=production nodemon server.js",
    "debug": "ndb server.js",
    "server": "nodemon server.js",
    "client": "cd client && npm start",    
    "build": "cd client && npm run build",    
    "dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
    "start": "node server.js",
    "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"    
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "compression": "^1.7.4",
    "concurrently": "^5.1.0",
    "cookie-parser": "^1.4.4",
    "cors": "^2.8.5",
    "dotenv": "^8.1.0",
    "express": "^4.17.1",
    "express-mongo-sanitize": "^1.3.2",
    "express-rate-limit": "^5.0.0",
    "helmet": "^3.21.1",
    "hpp": "^0.2.2",
    "html-to-text": "^5.1.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.7.1",
    "morgan": "^1.9.1",
    "multer": "^1.4.2",
    "ndb": "^1.1.5",
    "nodemailer": "^6.3.0",
    "path": "^0.12.7",
    "pug": "^2.0.4",
    "slugify": "^1.3.5",
    "stripe": "^7.9.1",
    "validator": "^11.1.0",
    "xss-clean": "^0.1.1"
  },
  "engines": {
    "node": "^10"
  }
}

1 Answers1

0

Can you try this-

That is server.js file contents:-

const express = require("express");
const path = require("path");
const app = express();
require("dotenv").config();
app.use(express.static(path.join(__dirname, "build")));

app.get("/", function(req, res) {
  res.sendFile(path.join(__dirname, "build", "index.html"));
});

app.get("/*", function(req, res) {
  res.sendFile(path.join(__dirname, "build", "index.html"));
});

app.listen(process.env.PORT || 3000);

That is my script part:-

  "scripts": {
    "start:production": "npm install && npm run build && npm run start:prod",
    "start:prod": "cross-env NODE_ENV=production node server",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Start command in production:-

npm run start:production
Ankit Kumar Rajpoot
  • 5,188
  • 2
  • 38
  • 32
  • Hey Ankit, I tried the code you recomended but got the following message. Also I really appreciate your help :): – alexander95371 Feb 14 '20 at 03:28
  • react-scripts: command not found npm ERR! code ELIFECYCLE npm ERR! syscall spawn npm ERR! file sh npm ERR! errno ENOENT npm ERR! clear@1.0.0 build: `react-scripts build` npm ERR! spawn ENOENT npm ERR! n – alexander95371 Feb 14 '20 at 03:28
  • When I deploy locally I get the following [OKAY] package.json file found - trying 'npm start' 7:46:15 PM web.1 | > clear@1.0.0 start /Users/test/app-name 7:46:15 PM web.1 | > node server.js 7:46:22 PM web.1 | Listening on port 5000 7:46:24 PM web.1 | connected to Mongodb 7:49:58 PM web.1 | GET / 404 15.140 ms - 139 – alexander95371 Feb 14 '20 at 03:51