Search code examples
node.jsreactjsexpressmongoosenodemailer

Failed at the app@1.0.0 start script This is probably not a problem with npm. There is likely additional logging output above


Hi Guys, I have created a little project of Mern stack. I am deploying it correctly on Heroku. But as soon as I am checking her on Heroku after deploying, then Failed to load resource: the server responded with a status of 503 (Service Unavailable) error is coming. But as soon as I run heroku local in cmd after deploying then it is working correctly. I am giving below the heroku setup code. Please guide me. please ........

enter image description here

package.sjon file of backend

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "npm install && node index",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "dependencies": {
    "config": "^3.3.1",
    "express": "~4.16.1",
    "express-fileupload": "^1.1.7-alpha.3",
    "mongoose": "^5.9.12",
    "nodemailer": "^6.4.6"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Index.js file of backend

var express = require('express');
var path = require('path');
const connectDB = require('./config/db')
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var studentRouter = require('./routes/student')

var app = express();

connectDB();


app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

app.use(express.static('client/build'))
app.get('/', (req, res) => {
    res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})

app.use('/', indexRouter);
app.use('/', studentRouter);
app.use('/users', usersRouter);


if (process.env.NODE_ENV == "production") {
    app.use(express.static('client/build'))
    app.get('*', (req, res) => {
        res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
    })
}



var port = process.env.PORT || '8000';
app.listen(port, () => {
    console.log(`server run port ${port}`);
})

module.exports = app;

Solution

  • All these codes are absolutely correct. I had a problem creating a cluster in mongodb atlas. The problem was that I had selected add current ip address while creating the cluster. Whereas I had to select allow from anywhere. So now I have selected the book. And now it is doing the right thing.

    enter image description here