Problem in deploying MERN App to heroku

I have a problem in while deploying my MERN app on Heroku
But it is running on localhost:5006 perfectly
This is the error which I am getting


C:\Users\user\Desktop\try\CallLogJavascriptAuth>heroku logs
2020-05-03T15:07:07.638281+00:00 app[web.1]: npm ERR! Failed at the javascriptauth@1.0.0 start script.
2020-05-03T15:07:07.638424+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-03T15:07:07.646693+00:00 app[web.1]: 
2020-05-03T15:07:07.646866+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-03T15:07:07.646950+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-05-03T15_07_07_639Z-debug.log
2020-05-03T15:07:07.718773+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-03T15:18:37.000000+00:00 app[api]: Build started by user goyalrajat8696@gmail.com
2020-05-03T15:18:52.809986+00:00 app[api]: Deploy 88d999b6 by user goyalrajat8696@gmail.com
2020-05-03T15:18:52.809986+00:00 app[api]: Release v8 created by user goyalrajat8696@gmail.com
2020-05-03T15:18:53.589055+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-03T15:18:53.000000+00:00 app[api]: Build succeeded
2020-05-03T15:18:57.958111+00:00 app[web.1]: 
2020-05-03T15:18:57.958134+00:00 app[web.1]: > javascriptauth@1.0.0 start /app
2020-05-03T15:18:57.958135+00:00 app[web.1]: > node app.js
2020-05-03T15:18:57.958135+00:00 app[web.1]: 
2020-05-03T15:18:58.397180+00:00 app[web.1]: internal/modules/cjs/loader.js:960
2020-05-03T15:18:58.397223+00:00 app[web.1]: throw err;
2020-05-03T15:18:58.397223+00:00 app[web.1]: ^
2020-05-03T15:18:58.397223+00:00 app[web.1]: 
2020-05-03T15:18:58.397224+00:00 app[web.1]: Error: Cannot find module '../config/auth'
2020-05-03T15:18:58.397224+00:00 app[web.1]: Require stack:
2020-05-03T15:18:58.397225+00:00 app[web.1]: - /app/Routes/index.js
2020-05-03T15:18:58.397225+00:00 app[web.1]: - /app/app.js
2020-05-03T15:18:58.397226+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
2020-05-03T15:18:58.397226+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:840:27)
2020-05-03T15:18:58.397227+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-05-03T15:18:58.397227+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-05-03T15:18:58.397228+00:00 app[web.1]: at Object.<anonymous> (/app/Routes/index.js:5:55)
2020-05-03T15:18:58.397228+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-05-03T15:18:58.397228+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-05-03T15:18:58.397228+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32)
2020-05-03T15:18:58.397229+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14)
2020-05-03T15:18:58.397229+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-05-03T15:18:58.397229+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-05-03T15:18:58.397229+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:4:15)
2020-05-03T15:18:58.397230+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-05-03T15:18:58.397230+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-05-03T15:18:58.397230+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32)
2020-05-03T15:18:58.397230+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14) {
2020-05-03T15:18:58.397231+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-05-03T15:18:58.397231+00:00 app[web.1]: requireStack: [ '/app/Routes/index.js', '/app/app.js' ]
2020-05-03T15:18:58.397231+00:00 app[web.1]: }
2020-05-03T15:18:58.407083+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-03T15:18:58.407298+00:00 app[web.1]: npm ERR! errno 1
2020-05-03T15:18:58.408284+00:00 app[web.1]: npm ERR! javascriptauth@1.0.0 start: `node app.js`
2020-05-03T15:18:58.408380+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-03T15:18:58.408499+00:00 app[web.1]: npm ERR!
2020-05-03T15:18:58.408591+00:00 app[web.1]: npm ERR! Failed at the javascriptauth@1.0.0 start script.
2020-05-03T15:18:58.408676+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-03T15:18:58.413615+00:00 app[web.1]:
2020-05-03T15:18:58.413760+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-03T15:18:58.413826+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-05-03T15_18_58_409Z-debug.log
2020-05-03T15:18:58.492310+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-03T15:18:58.497009+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-03T15:19:02.339266+00:00 app[web.1]:
2020-05-03T15:19:02.339286+00:00 app[web.1]: > javascriptauth@1.0.0 start /app
2020-05-03T15:19:02.339286+00:00 app[web.1]: > node app.js
2020-05-03T15:19:02.339287+00:00 app[web.1]: 
2020-05-03T15:19:02.758247+00:00 app[web.1]: internal/modules/cjs/loader.js:960
2020-05-03T15:19:02.758271+00:00 app[web.1]: throw err;
2020-05-03T15:19:02.758271+00:00 app[web.1]: ^
2020-05-03T15:19:02.758272+00:00 app[web.1]:
2020-05-03T15:19:02.758272+00:00 app[web.1]: Error: Cannot find module '../config/auth'
2020-05-03T15:19:02.758272+00:00 app[web.1]: Require stack:
2020-05-03T15:19:02.758273+00:00 app[web.1]: - /app/Routes/index.js
2020-05-03T15:19:02.758273+00:00 app[web.1]: - /app/app.js
2020-05-03T15:19:02.758274+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
2020-05-03T15:19:02.758275+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:840:27)
2020-05-03T15:19:02.758275+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-05-03T15:19:02.758275+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-05-03T15:19:02.758276+00:00 app[web.1]: at Object.<anonymous> (/app/Routes/index.js:5:55)
2020-05-03T15:19:02.758276+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-05-03T15:19:02.758277+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-05-03T15:19:02.758277+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32)
2020-05-03T15:19:02.758277+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14)
2020-05-03T15:19:02.758278+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-05-03T15:19:02.758278+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-05-03T15:19:02.758278+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:4:15)
2020-05-03T15:19:02.758279+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-05-03T15:19:02.758279+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-05-03T15:19:02.758279+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32)
2020-05-03T15:19:02.758280+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14) {
2020-05-03T15:19:02.758280+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-05-03T15:19:02.758280+00:00 app[web.1]: requireStack: [ '/app/Routes/index.js', '/app/app.js' ]
2020-05-03T15:19:02.758281+00:00 app[web.1]: }
2020-05-03T15:19:02.766577+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-03T15:19:02.766873+00:00 app[web.1]: npm ERR! errno 1
2020-05-03T15:19:02.767877+00:00 app[web.1]: npm ERR! javascriptauth@1.0.0 start: `node app.js`
2020-05-03T15:19:02.768032+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-03T15:19:02.768204+00:00 app[web.1]: npm ERR!
2020-05-03T15:19:02.768353+00:00 app[web.1]: npm ERR! Failed at the javascriptauth@1.0.0 start script.
2020-05-03T15:19:02.768441+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-03T15:19:02.775054+00:00 app[web.1]:
2020-05-03T15:19:02.775207+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-03T15:19:02.775286+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-05-03T15_19_02_769Z-debug.log
2020-05-03T15:19:02.853423+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-03T15:19:12.444966+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=still-savannah-82332.herokuapp.com request_id=264c522c-a76d-4c51-b3de-9d25720a6e15 fwd="106.207.136.78" dyno= connect= service= status=503 bytes= protocol=https
2020-05-03T15:19:14.598988+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-savannah-82332.herokuapp.com request_id=7da4a645-4ad6-49d3-8e4b-73690f9dc29b fwd="106.207.136.78" dyno= connect= service= status=503 bytes= protocol=https
2020-05-03T15:29:43.147291+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=still-savannah-82332.herokuapp.com request_id=5d64330e-2394-4b59-b914-3d3250a9dca0 fwd="106.207.136.78" dyno= connect= service= status=503 bytes= protocol=https
2020-05-03T15:29:44.860760+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-savannah-82332.herokuapp.com request_id=905d18b2-a7af-453e-8dc9-559db5059e9c fwd="106.207.136.78" dyno= connect= service= status=503 bytes= protocol=https

I have used Node Js, express, Ejs and MongoDb in my project
This is my app.js file

const express = require("express");
const expressLayouts = require("express-ejs-layouts");
const app = express();
const index = require("./Routes/index");
const users = require("./Routes/users");
const contact = require("./Routes/contact");
const mongoose = require("mongoose");
const cors = require("cors");
const flash = require("connect-flash");
const passport = require("passport");
const session = require("express-session");

//to show a msg after redirect we can use connect-flash
//express session middleware
app.use(
  session({
    secret: "My secret",
    resave: true,
    saveUninitialized: true,
  })
);

//middleware for the passportjs
app.use(passport.initialize());
app.use(passport.session());

//passport config file
require("./config/passport")(passport);

//add middleware to connect flash
app.use(flash());
//global var for colurs

app.use((req, res, next) => {
  res.locals.success_msg = req.flash("success_msg");
  res.locals.error_msg = req.flash("err_msg");
  res.locals.error = req.flash("error");
  res.locals.error_log = req.flash("error_log");
  next();
});

app.use(cors());
//config
const db = require("./config/keys").MongoURI;
//Connect Mongo
mongoose.set("useNewUrlParser", true);
mongoose.set("useFindAndModify", false);
mongoose.set("useCreateIndex", true);
mongoose.set("useUnifiedTopology", true);
mongoose
  .connect(db)
  .then(() => console.log("MongoDb Connected!!"))
  .catch((err) => console.log(err));

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

app.use(expressLayouts);
app.set("view engine", "ejs");
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

// app.get("/", (req, res) => {
//   res.render("welcome");
// });

app.use("/", index);
app.use("/users", users);
app.use("/send/contact", contact);

app.listen(port, console.log(`Server is running on ${port}`));

And this is package.json file

{
  "name": "javascriptauth",
  "version": "1.0.0",
  "description": "This is guide to js authentication",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
    "dev": "nodemon app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Hackrx",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "connect-flash": "^0.1.1",
    "cors": "^2.8.5",
    "ejs": "^3.1.2",
    "express": "^4.17.1",
    "express-ejs-layouts": "^2.5.0",
    "express-session": "^1.17.1",
    "mongoose": "^5.9.10",
    "passport": "^0.4.1",
    "passport-local": "^1.0.0"
  }
}

This is my procfile inside Root folder

web: npm app.js

.env file

PORT = 8081

index.js file which is ./Routes/

const express = require("express");
const Contact = require("../models/newcontact.model");

const router = express.Router();
const { ensureAuthenticated, forwardAuthenticated } = require("../config/auth");

router.get("/", forwardAuthenticated, (req, res) => {
  res.render("welcome");
});

router.get("/dashboard", ensureAuthenticated, (req, res) => {
  Contact.find()
    .then((cont) => {
      res.render("dashboard", {
        contactlist: cont,
      });
    })
    .catch((err) => console.log(err));
});

router.get("/userwel", ensureAuthenticated, (req, res) => {
  // req.flash("success_msg", "You need to logout first to visit login page!!");
  res.render("welcome2", {
    success_msg: "You need to logout first to visit login page!!",
  });
});

module.exports = router;

This is my welcome.ejs file which is in the ./views/welcome.ejs from the Root folder

<div class="row">
  <div
    style="
      margin: 30px auto;
      width: 50%;
      padding: 1.2rem;
      border-radius: 1.2rem;
      border: 0.4px solid #1967be;
    "
  >
    <div class="card card-body text-center">
      <h1><i class="fab fa-node-js fa-3x"></i></h1>
      <p>Create an account or login</p>
      <a
        href="/users/register"
        class="btn btn-primary btn-block mb-2"
        style="border-radius: 2.2rem;"
        >Register</a
      >
      <a
        href="/users/login"
        style="border-radius: 2.2rem;"
        class="btn btn-primary btn-block mb-2"
        >Login</a
      >
    </div>
  </div>
</div>

And this is my folder structure


Please help me.I have listed all the files above.

Well, i guess you already saw the problem now:

Error: Cannot find module '../config/auth'

Why this happens on Heroku and not locally i don’t know…that said have you already tried to change the import statement?

I have used this import statement inside users.js

const express = require("express");
const router = express.Router();
const User = require("../models/User");
const bcrypt = require("bcryptjs");
const passport = require("passport");
const { ensureAuthenticated, forwardAuthenticated } = require("../config/auth");
router.get("/login", forwardAuthenticated, (req, res) => {
  res.render("login");
});

router.get("/register", forwardAuthenticated, (req, res) => {
  res.render("register");
});

//Register

router.post("/register", (req, res) => {
  console.log(req.body);
  const { name, email, password, password2 } = req.body;

  let errors = [];
  //email validation
  if (!name || !email || !password || !password2) {
    errors.push({ msg: "Please fill all fields" });
  }

  //password match
  if (password !== password2) {
    errors.push({ msg: "Password do not matches " });
  }

  //check for pass length
  if (password.length <= 5) {
    errors.push({ msg: "Password must be greater then 6 characters " });
  }

  if (errors.length > 0) {
    res.render("register", {
      errors,
      name,
      email,
      password,
      password2,
    });
  } else {
    User.findOne({ email: email }).then((user) => {
      //
      if (user) {
        errors.push({ msg: "User email already exists!!" });
        res.render("register", {
          errors,
          name,
          email,
          password,
          password2,
        });
      } else {
        const newUser = new User({
          name,
          email,
          password,
        });
        console.log(newUser);

        //Encrypting the password
        bcrypt.genSalt(10, (err, salt) =>
          bcrypt.hash(newUser.password, salt, (err, hash) => {
            if (err) throw err;
            //Set password to hash
            newUser.password = hash;
            newUser
              .save()
              .then((user) => {
                req.flash(
                  "success_msg",
                  "You are now successfully registered and can login!!"
                );

                res.redirect("/users/login");
              })
              .catch((err) => {
                console.log(err);
                errors.push({ msg: err.errmsg });
              });
          })
        );
      }
    });
  }
});

//Login handling
//Handling post request

router.post("/login", (req, res, next) => {
  passport.authenticate("local", {
    successRedirect: "/dashboard",
    failureRedirect: "/users/login",
    failureFlash: true,
  })(req, res, next);
});

//Logout handle
router.get("/logout", (req, res) => {
  req.logout();
  req.flash("success_msg", "You are logged out ");

  res.redirect("/users/login");
});

module.exports = router;

You can see my folder tree structure and I think it is accordingly correct.

Of course it is!
But i think there could be a problem when deploying, dunno ^^
Just a guessing! :grin:

I too faced similar issue It gets resolved by removing port variable in by env. Heroku sometimes can’t deploy the app at the port that we specified, its always better to leave the port variable empty. At runtime heroku will asign a value to the PORT variable so the app runs fine.

So remove the port and give a try

No, it didn’t work for me, still, I am facing the same error

C:\Users\user\Desktop\try\CallLogJavascriptAuth>heroku logs
2020-05-04T15:20:40.489978+00:00 app[web.1]: npm ERR!
2020-05-04T15:20:40.490057+00:00 app[web.1]: npm ERR! Failed at the javascriptauth@1.0.0 start script.
2020-05-04T15:20:40.490132+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-04T15:20:40.494060+00:00 app[web.1]:
2020-05-04T15:20:40.494198+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-04T15:20:40.494274+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-05-04T15_20_40_490Z-debug.log
2020-05-04T15:20:40.568624+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-04T17:53:18.000000+00:00 app[api]: Build started by user goyalrajat8696@gmail.com
2020-05-04T17:53:34.221788+00:00 app[api]: Deploy a6833e33 by user goyalrajat8696@gmail.com
2020-05-04T17:53:34.221788+00:00 app[api]: Release v10 created by user goyalrajat8696@gmail.com
2020-05-04T17:53:34.883379+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-04T17:53:34.000000+00:00 app[api]: Build succeeded
2020-05-04T17:53:47.584675+00:00 app[web.1]:
2020-05-04T17:53:47.584710+00:00 app[web.1]: > javascriptauth@1.0.0 start /app
2020-05-04T17:53:47.584711+00:00 app[web.1]: > node app.js
2020-05-04T17:53:47.584711+00:00 app[web.1]:
2020-05-04T17:53:48.197757+00:00 app[web.1]: internal/modules/cjs/loader.js:960
2020-05-04T17:53:48.197783+00:00 app[web.1]: throw err;
2020-05-04T17:53:48.197783+00:00 app[web.1]: ^
2020-05-04T17:53:48.197784+00:00 app[web.1]:
2020-05-04T17:53:48.197785+00:00 app[web.1]: Error: Cannot find module '../config/auth'
2020-05-04T17:53:48.197785+00:00 app[web.1]: Require stack:
2020-05-04T17:53:48.197786+00:00 app[web.1]: - /app/Routes/index.js
2020-05-04T17:53:48.197786+00:00 app[web.1]: - /app/app.js
2020-05-04T17:53:48.197789+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
2020-05-04T17:53:48.197789+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:840:27)
2020-05-04T17:53:48.197790+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-05-04T17:53:48.197790+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-05-04T17:53:48.197790+00:00 app[web.1]: at Object.<anonymous> (/app/Routes/index.js:5:55)
2020-05-04T17:53:48.197791+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-05-04T17:53:48.197791+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-05-04T17:53:48.197791+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32)
2020-05-04T17:53:48.197792+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14)
2020-05-04T17:53:48.197792+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-05-04T17:53:48.197793+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-05-04T17:53:48.197793+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:4:15)
2020-05-04T17:53:48.197793+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-05-04T17:53:48.197794+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-05-04T17:53:48.197794+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32)
2020-05-04T17:53:48.197794+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14) {
2020-05-04T17:53:48.197794+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-05-04T17:53:48.197795+00:00 app[web.1]: requireStack: [ '/app/Routes/index.js', '/app/app.js' ]
2020-05-04T17:53:48.197795+00:00 app[web.1]: }
2020-05-04T17:53:48.206153+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-04T17:53:48.206515+00:00 app[web.1]: npm ERR! errno 1
2020-05-04T17:53:48.208153+00:00 app[web.1]: npm ERR! javascriptauth@1.0.0 start: `node app.js`
2020-05-04T17:53:48.208338+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-04T17:53:48.208560+00:00 app[web.1]: npm ERR!
2020-05-04T17:53:48.208731+00:00 app[web.1]: npm ERR! Failed at the javascriptauth@1.0.0 start script.
2020-05-04T17:53:48.208899+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-04T17:53:48.217018+00:00 app[web.1]:
2020-05-04T17:53:48.217219+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-04T17:53:48.217370+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-05-04T17_53_48_209Z-debug.log
2020-05-04T17:53:48.302308+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-04T17:53:48.305104+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-04T17:53:52.740059+00:00 app[web.1]:
2020-05-04T17:53:52.740072+00:00 app[web.1]: > javascriptauth@1.0.0 start /app
2020-05-04T17:53:52.740073+00:00 app[web.1]: > node app.js
2020-05-04T17:53:52.740073+00:00 app[web.1]:
2020-05-04T17:53:53.231244+00:00 app[web.1]: internal/modules/cjs/loader.js:960
2020-05-04T17:53:53.231279+00:00 app[web.1]: throw err;
2020-05-04T17:53:53.231279+00:00 app[web.1]: ^
2020-05-04T17:53:53.231279+00:00 app[web.1]:
2020-05-04T17:53:53.231280+00:00 app[web.1]: Error: Cannot find module '../config/auth'
2020-05-04T17:53:53.231280+00:00 app[web.1]: Require stack:
2020-05-04T17:53:53.231281+00:00 app[web.1]: - /app/Routes/index.js
2020-05-04T17:53:53.231281+00:00 app[web.1]: - /app/app.js
2020-05-04T17:53:53.231282+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
2020-05-04T17:53:53.231282+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:840:27)
2020-05-04T17:53:53.231283+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-05-04T17:53:53.231283+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-05-04T17:53:53.231284+00:00 app[web.1]: at Object.<anonymous> (/app/Routes/index.js:5:55)
2020-05-04T17:53:53.231284+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-05-04T17:53:53.231285+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-05-04T17:53:53.231285+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32)
2020-05-04T17:53:53.231286+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14)
2020-05-04T17:53:53.231286+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-05-04T17:53:53.231286+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-05-04T17:53:53.231287+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:4:15)
2020-05-04T17:53:53.231287+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-05-04T17:53:53.231287+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-05-04T17:53:53.231288+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32)
2020-05-04T17:53:53.231288+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14) {
2020-05-04T17:53:53.231288+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-05-04T17:53:53.231289+00:00 app[web.1]: requireStack: [ '/app/Routes/index.js', '/app/app.js' ]
2020-05-04T17:53:53.231289+00:00 app[web.1]: }
2020-05-04T17:53:53.238443+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-04T17:53:53.238726+00:00 app[web.1]: npm ERR! errno 1
2020-05-04T17:53:53.239707+00:00 app[web.1]: npm ERR! javascriptauth@1.0.0 start: `node app.js`
2020-05-04T17:53:53.239857+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-04T17:53:53.240022+00:00 app[web.1]: npm ERR!
2020-05-04T17:53:53.240153+00:00 app[web.1]: npm ERR! Failed at the javascriptauth@1.0.0 start script.
2020-05-04T17:53:53.240281+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-04T17:53:53.247107+00:00 app[web.1]:
2020-05-04T17:53:53.247304+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-04T17:53:53.247423+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-05-04T17_53_53_240Z-debug.log
2020-05-04T17:53:53.313632+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-04T17:53:54.804745+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=still-savannah-82332.herokuapp.com request_id=fa63f82b-d27a-482c-b330-9b22ca9886a9 fwd="106.207.128.117" dyno= connect= service= status=503 bytes= protocol=https
2020-05-04T17:53:55.104053+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/robots.txt" host=still-savannah-82332.herokuapp.com request_id=e7c85bb0-239b-42cc-8679-bfbc8792894e fwd="106.207.128.117" dyno= connect= service= status=503 bytes= protocol=https
2020-05-04T17:53:55.788866+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-savannah-82332.herokuapp.com request_id=6cfb68bd-c1dd-4709-9634-5d19bf71db6d fwd="106.207.128.117" dyno= connect= service= status=503 bytes= protocol=https

My .env file

PORT =

I have used the following commands to deploy my app to Heroku

  1. heroku login
    2.heroku create
  2. git add .
  3. git commit -m "My first App"
  4. git push heroku master
  5. heroku open

Then I faced Application error on https://still-savannah-82332.herokuapp.com/

Hello!

Try removing your .env entirely.

You should not commit the .env file and instead configure the Heroku app using the Settings page -> Config Vars of your app page.

Otherwise, if that doesn’t work either, could you share your code?

Edit

For anyone reading this, the idea of having the .env files is to have different environments or configurations. For instance, when you’re testing locally, you may have a local database, not accessible by anyone else, hence your connection string may (and should) differ from the one used by a collaborator or the one used in production (once your application is available to the public/internet).

On a production environment you could setup every variable in the shell (Windows CMD, Linux terminal, etc.) environment, so it’s harder to get access to it.

When testing, you could have an .env.test file with different values, like a different database so you don’t mess with the data on your development database nor your production database.

For more information, take a look at the Twelve-Factor app.

This problem is related to ignoreCase in git and if you rename a file in local it works but on linux server it will give error
simple fix
vim .git/config and then set
ignorecase = false

git commit and push the code again it worked for me

Hii, I tried your solution but it didn’t work, I am not committing the .env file.
You can also look at .gitignore file

/node_modules
npm-debug.log
.DS_Store
/.env
/config

I tried your solution, it didn’t worked for me. :frowning: