Heroku keep crashing after Starting process with command `npm start' - node.js

I am newbie. I am following Tutorial from https://www.sitepoint.com/building-facebook-chat-bot-node-heroku/ to make sample facebook messenger bot.
Just when I deployed it first time in heroku I got error
Here is my package.json
{
"name": "spbot",
"version": "1.0.0",
"description": "Testbot",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "Munkh",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
"mongoose": "^4.9.1",
"request": "^2.81.0"
}
}
here is app.js
var express = require("express");
var request = require("request");
var bodyParser = require("body-parser");
var app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.listen((process.env.PORT || 5000));
// Server index page
app.get("/", function (req, res) {
res.send("Deployed!");
});
// Facebook Webhook
// Used for verification
app.get("/webhook", function (req, res) {
if (req.query["hub.verify_token"] === "this_is_my_token") {
console.log("Verified webhook");
res.status(200).send(req.query["hub.challenge"]);
} else {
console.error("Verification failed. The tokens do not match.");
res.sendStatus(403);
}
});
I got error like this
2017-03-20T02:11:15.997279+00:00 heroku[web.1]: State changed from crashed to starting
2017-03-20T02:11:17.849748+00:00 heroku[web.1]: Starting process with command `npm start`
2017-03-20T02:11:20.455381+00:00 app[web.1]:
2017-03-20T02:11:20.455396+00:00 app[web.1]: > spbot#1.0.0 start /app
2017-03-20T02:11:20.455397+00:00 app[web.1]: > node app.js
2017-03-20T02:11:20.455397+00:00 app[web.1]:
2017-03-20T02:11:20.978077+00:00 heroku[web.1]: Process exited with status 0
2017-03-20T02:11:20.994169+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-20T02:11:20.994986+00:00 heroku[web.1]: State changed from crashed to starting
2017-03-20T02:11:23.337790+00:00 heroku[web.1]: Starting process with command `npm start`
2017-03-20T02:11:27.660508+00:00 app[web.1]:
2017-03-20T02:11:27.660527+00:00 app[web.1]: > node app.js
2017-03-20T02:11:27.660526+00:00 app[web.1]: > spbot#1.0.0 start /app
2017-03-20T02:11:27.660528+00:00 app[web.1]:
2017-03-20T02:11:27.896343+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-20T02:11:27.881546+00:00 heroku[web.1]: Process exited with status 0
Because error doesn't specify what went wrong and just keep crashing, I can't find a solution. My apologies if it is simple question.

You have to specify the node.js and npm version which you are using in package.json, as mentioned below.
Specify the versions which you are using in your development.
{
"name": "spbot",
"version": "1.0.0",
"description": "Testbot",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "Munkh",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
"mongoose": "^4.9.1",
"request": "^2.81.0"
},
"engines": {
"node": "7.0.0",
"npm": "3.10.8"
}
}

Related

Server is not starting or connecting when using Nodemon

I just setup a new project using Express, Node and Nodemon. I setup the basics of the file to make sure it is starting but when I'm using npm start in the terminal it appears to start but it doesn't get a message of where the server has been started and when checking the localhost it is not connected. Not sure what the issue is.
below is my package.json
{
"name": "resturant-picker",
"version": "1.0.0",
"description": "Resturant picker app for Alchs",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/connordensmore/resturant-picker.git"
},
"keywords": [
"crud",
"mongodb"
],
"author": "Connor",
"license": "ISC",
"bugs": {
"url": "https://github.com/connordensmore/resturant-picker/issues"
},
"homepage": "https://github.com/connordensmore/resturant-picker#readme",
"dependencies": {
"axios": "^0.27.2",
"body-parser": "^1.20.0",
"dotenv": "^16.0.2",
"ejs": "^3.1.8",
"express": "^4.18.1",
"mongoose": "^6.5.5",
"morgan": "^1.10.0",
"node": "^18.8.0",
"nodemon": "^2.0.19"
}
}
below is my server.js
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
app.get("/", (req, res) => {
res.send("Crud App");
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
});
when i run npm start in the terminal this is the response and then nothing happens or is started from what i can tell.
mopdog#Connors-MacBook-Pro resturant-picker % npm start
> resturant-picker#1.0.0 start
> nodemon server.js
[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
[nodemon] clean exit - waiting for changes before restart
You never run listen because it's inside another function.
app.get("/", (req, res) => {
res.send("Crud App");
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});

PORT error when deploying a nodejs application to Heroku

I am trying to deploy my nodejs app on heroku. The build is successful however I am getting these errors:
2020-01-20T23:39:44.000000+00:00 app[api]: Build succeeded
2020-01-20T23:39:46.924595+00:00 heroku[web.1]: Starting process with command `npm install --only=dev && npm run client-install && npm run dev`
2020-01-20T23:39:50.661227+00:00 app[web.1]: npm WARN jackpot#1.0.0 No repository field.
2020-01-20T23:39:50.661677+00:00 app[web.1]:
2020-01-20T23:39:50.704813+00:00 app[web.1]: audited 530 packages in 1.693s
2020-01-20T23:39:50.833913+00:00 app[web.1]:
2020-01-20T23:39:50.833917+00:00 app[web.1]: 4 packages are looking for funding
2020-01-20T23:39:50.833919+00:00 app[web.1]: run `npm fund` for details
2020-01-20T23:39:50.833921+00:00 app[web.1]:
2020-01-20T23:39:50.834704+00:00 app[web.1]: found 0 vulnerabilities
2020-01-20T23:39:50.834706+00:00 app[web.1]:
2020-01-20T23:39:51.165784+00:00 app[web.1]:
2020-01-20T23:39:51.165819+00:00 app[web.1]: > jackpot#1.0.0 client-install /app
2020-01-20T23:39:51.165823+00:00 app[web.1]: > npm install --prefix client
2020-01-20T23:39:51.165825+00:00 app[web.1]:
2020-01-20T23:40:43.615827+00:00 app[web.1]:
2020-01-20T23:40:43.615852+00:00 app[web.1]: > core-js#2.6.11 postinstall /app/client/node_modules/core-js
2020-01-20T23:40:43.615854+00:00 app[web.1]: > node -e "try{require('./postinstall')}catch(e){}"
2020-01-20T23:40:43.615856+00:00 app[web.1]:
2020-01-20T23:40:43.691296+00:00 app[web.1]: Thank you for using core-js ( https://github.com/zloirock/core-js ) for
polyfilling JavaScript standard library!
2020-01-20T23:40:43.691299+00:00 app[web.1]:
2020-01-20T23:40:43.691302+00:00 app[web.1]: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
2020-01-20T23:40:43.691305+00:00 app[web.1]: > https://opencollective.com/core-js
2020-01-20T23:40:43.691307+00:00 app[web.1]: > https://www.patreon.com/zloirock
2020-01-20T23:40:43.691309+00:00 app[web.1]:
2020-01-20T23:40:43.691311+00:00 app[web.1]: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
2020-01-20T23:40:43.691313+00:00 app[web.1]:
2020-01-20T23:40:43.705353+00:00 app[web.1]:
2020-01-20T23:40:43.705360+00:00 app[web.1]: > core-js-pure#3.6.4 postinstall /app/client/node_modules/core-js-pure
2020-01-20T23:40:43.705365+00:00 app[web.1]: > node -e "try{require('./postinstall')}catch(e){}"
2020-01-20T23:40:43.705368+00:00 app[web.1]:
2020-01-20T23:40:44.193688+00:00 app[web.1]:
2020-01-20T23:40:44.193702+00:00 app[web.1]: > core-js#3.6.4 postinstall /app/client/node_modules/react-app-polyfill/node_modules/core-js
2020-01-20T23:40:44.193707+00:00 app[web.1]: > node -e "try{require('./postinstall')}catch(e){}"
2020-01-20T23:40:44.193709+00:00 app[web.1]:
2020-01-20T23:40:47.195666+00:00 heroku[web.1]: State changed from starting to crashed
2020-01-20T23:40:47.199923+00:00 heroku[web.1]: State changed from crashed to starting
2020-01-20T23:40:47.087841+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-01-20T23:40:47.088001+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-01-20T23:40:47.175500+00:00 heroku[web.1]: Process exited with status 137
I did some research online and found that it is related to these lines: server.js:
const PORT = process.env.PORT || 7000;
app.listen(PORT, () => console.log(`Server up and running on port ${PORT} !`));
Only problem is that I have the client code doing API calls to the server, which requires me to a proxy.
server.js:
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
const users = require("./routes/api/users");
const app = express();
// Bodyparser middleware
app.use(
bodyParser.urlencoded({
extended: false
})
);
app.use(bodyParser.json());
// DB Config
const db = require("./config/keys").mongoURI;
// Connect to MongoDB
mongoose
.connect(
db,
{ useNewUrlParser: true,
useUnifiedTopology: true
}
)
.then(() => console.log("MongoDB successfully connected"))
.catch(err => console.log(err));
// Passport middleware
app.use(passport.initialize());
// Passport config
require("./config/passport")(passport);
// Routes
app.use("/api/users", users);
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server up and running on port ${PORT} !`));
server package.json:
{
"name": "jackpot",
"version": "1.0.0",
"description": "JackPot Application",
"main": "server.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\"",
"prod": "NODE_ENV=production concurrently \"npm run server\" \"npm run client\""
},
"author": "",
"license": "MIT",
"dependencies": {
"axios": "^0.19.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"concurrently": "^4.0.1",
"express": "^4.16.4",
"fs": "0.0.1-security",
"is-empty": "^1.2.0",
"jquery": "^3.4.1",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.3.11",
"nodemailer": "^6.4.2",
"particles-bg": "^2.4.7",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"readline": "^1.3.0",
"sweetalert2": "^9.5.4",
"validator": "^10.9.0",
"ws": "^7.2.1"
}
}
/client/package.json:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.1",
"classnames": "^2.2.6",
"jquery": "^3.4.1",
"jwt-decode": "^2.2.0",
"particles-bg": "^2.4.7",
"react": "^16.6.3",
"react-chat-window": "^1.2.1",
"react-dom": "^16.6.3",
"react-redux": "^7.1.3",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
I hope one of you guys can help me, I have been scratching my head for hours.

Why does my web-app work fine on localhost (npm run dev) but look like trash when deployed to heroku?

by the way, NOT a duplicate of 19
Javascript features work on localhost but not when deployed to Heroku
I am going to sleep so I can leave my tunneled localhost
up for now which is what I see when I run npm run dev from my machine. And by the way, I feel like this should be some sort of simple package.json fix, so here's my package.json:
{
"name": "hps_prework",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "node app.js",
"start": "node app.js",
"build": "next build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"engines": {
"node": "11.6.0"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#material-ui/core": "^3.9.2",
"#material-ui/icons": "^3.0.2",
"babel-loader": "^8.0.5",
"jquery": "^3.3.1",
"js-cookie": "^2.2.0",
"koa": "^2.7.0",
"koa-session": "^5.10.1",
"next": "^8.0.3",
"python-shell": "^1.0.7",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-scripts": "^2.1.8",
"webpack": "^4.28.3"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
But here is what my app looks like deployed to heroku:
and here is the console output:
which leads me to believe some resources aren't being loaded for some reason.
What am I missing? repo
Lastly, this is heroku logs --tail ...
2019-03-21T05:40:54.000000+00:00 app[api]: Build succeeded 2019-03-
21T05:41:00.603480+00:00 heroku[web.1]: Starting process with command `npm
start` 2019-03-21T05:41:03.185110+00:00 app[web.1]: 2019-03-
21T05:41:03.185129+00:00 app[web.1]: > hps_prework#1.0.0 start /app 2019-03-
21T05:41:03.185131+00:00 app[web.1]: > node app.js 2019-03-
21T05:41:03.185132+00:00 app[web.1]: 2019-03-21T05:41:03.463015+00:00
app[web.1]: > Ready on http://localhost:25866 2019-03-
21T05:41:04.432538+00:00 heroku[web.1]: State changed from starting to up
2019-03-21T05:41:06.070888+00:00 heroku[router]: at=info method=GET path="/"
host=summaraize.herokuapp.com request_id=96091bf7-f9c1-45f1-b3b9-
5b74ce58826f fwd="104.38.101.109" dyno=web.1 connect=0ms service=517ms
status=200 bytes=3943 protocol=https
Nextjs docs custom server package.json instructions:
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
}
Example app using a custom server (express in this case) mars/heroku-nextjs-custom-server-express’s package.json:
"scripts": {
"dev": "node server.js -p $PORT",
  "build": "next build",
  "heroku-postbuild": "next build",
  "start": "node server.js -p $PORT"
},
Your package.json:
You should add the heroku-postbuild script and set NODE_ENV and/or PORT in your start script if needed.

NodeJS website uploaded to Heroku won't load, can't find dependencies for some reason

Tried to upload my website to an Heroku server.
It's not my first time and I usefully do not encounter any problems. I have added a profcile.
This is the package.json:
{
"name": "exodia-coming-soon",
"version": "1.0.0",
"description": "Coming Soon\r http://exodia.io",
"main": "server.js",
"dependencies": {
"express": "^4.16.3",
"nodemon": "^1.18.4",
"path": "^0.12.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Amirh24/exodia-landing.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Amirh24/exodia-landing/issues"
},
"homepage": "https://github.com/Amirh24/exodia-landing#readme"
}
What matters is the dependencies and
devDependencies part.
When I upload it to heroku and it wont load, the logs show:
2018-09-26T12:09:21.012703+00:00 app[web.1]: > exodia-coming-soon#1.0.0 start /app
2018-09-26T12:09:21.012705+00:00 app[web.1]: > nodemon server.js
2018-09-26T12:09:21.012706+00:00 app[web.1]:
2018-09-26T12:09:21.107321+00:00 app[web.1]: module.js:550
2018-09-26T12:09:21.107325+00:00 app[web.1]: throw err;
2018-09-26T12:09:21.107326+00:00 app[web.1]: ^
2018-09-26T12:09:21.107329+00:00 app[web.1]: Error: Cannot find module '../lib/cli'
When I try to start without nodemon, just node server.js I get:
2018-09-26T11:49:07.146721+00:00 app[web.1]: > node server.js
2018-09-26T11:49:07.146723+00:00 app[web.1]:
2018-09-26T11:49:07.257964+00:00 app[web.1]: module.js:550
2018-09-26T11:49:07.257968+00:00 app[web.1]: throw err;
2018-09-26T11:49:07.257969+00:00 app[web.1]: ^
2018-09-26T11:49:07.257971+00:00 app[web.1]:
2018-09-26T11:49:07.257973+00:00 app[web.1]: Error: Cannot find module './lib/express'
I have installed my 3 dependencies: express, path and nodemon a couple of times with both --save and -g variants. What am I doing wrong?
Where is that error being thrown? It looks like you're trying to use files in a relative position, not express in node_modules. Does your project have a lib folder? Are you uploading it as well?
You can uninstall the global express with npm uninstall -g express. Delete your node_modules folder and start fresh with npm install and npm start. Does it run locally?

NodeJS and Webpack on Heroku

I am simply trying to deploy a very straight forward nodejs server and webpack application to heroku but i get the following error from Heroku:
2018-03-26T12:02:19.952603+00:00 app[web.1]: webpack: Compiled successfully.
2018-03-26T11:52:19.406889+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-03-26T11:52:19.406889+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-03-26T11:52:19.486385+00:00 heroku[web.1]: Process exited with status 137
2018-03-26T11:52:19.497230+00:00 heroku[web.1]: State changed from starting to crashed
Seems like there is something wrong with the port but i am not sure what else i could do. Here is what my node looks like:
/* jshint esversion: 6 */
var express = require('express');
var path = require('path');
var serveStatic = require('serve-static');
app = express();
app.use(serveStatic(__dirname + "/dist"));
var port = process.env.PORT || 5000;
app.listen(port);
and my package.json:
{
"name": "xxx",
"version": "1.0.0",
"description": "xxxx",
"main": "index.html",
"scripts": {
"start": "npm run serve",
"serve": "webpack-dev-server --colors --watch --inline --progress --content-base /src --config config/webpack.dev.js",
"test:js": "eslint src/js/**",
"test:scss": "stylelint src/scss/**/*.scss",
"test": "npm run test:js && npm run test:scss",
"build": "npm run build:dev",
"build:dev": "ENV=dev webpack --config config/webpack.dev.js",
"build:prod": "npm run clean && ENV=prod webpack --config config/webpack.prod.js",
"clean": "rimraf -- dist",
"clean:all": "rimraf -- node_modules dist"
},
"license": "UNLICENSED",
"repository": {
"type": "git",
"url": "git+https://github.com/xxx/xxxx.git"
},
"keywords": [
"design",
"site",
"front-end"
],
"author": "xxxx",
"dependencies": {
...
},
"devDependencies": {
...
}
}

Resources