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.