PORT error when deploying a nodejs application to Heroku - node.js

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.

Related

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.

Issues when Hosting express with typescript and react app on Heroku

When hosting my app I get the following errors
2018-07-03T23:32:25.175363+00:00 heroku[web.1]: Starting process with command `npm start`
2018-07-03T23:32:28.093779+00:00 heroku[web.1]: State changed from starting to crashed
2018-07-03T23:32:27.719911+00:00 app[web.1]:
2018-07-03T23:32:27.719929+00:00 app[web.1]: > doombot#1.0.0 start /app
2018-07-03T23:32:27.719931+00:00 app[web.1]: > node src/server/dist/server.js
2018-07-03T23:32:27.719932+00:00 app[web.1]:
2018-07-03T23:32:27.942441+00:00 app[web.1]: module.js:545
2018-07-03T23:32:27.942444+00:00 app[web.1]: throw err;
2018-07-03T23:32:27.942446+00:00 app[web.1]: ^
2018-07-03T23:32:27.942447+00:00 app[web.1]:
2018-07-03T23:32:27.942449+00:00 app[web.1]: Error: Cannot find module '/app/src/server/dist/server.js'
2018-07-03T23:32:27.942451+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:543:15)
2018-07-03T23:32:27.942453+00:00 app[web.1]: at Function.Module._load (module.js:470:25)
2018-07-03T23:32:27.942454+00:00 app[web.1]: at Function.Module.runMain (module.js:690:10)
2018-07-03T23:32:27.942456+00:00 app[web.1]: at startup (bootstrap_node.js:194:16)
2018-07-03T23:32:27.942457+00:00 app[web.1]: at bootstrap_node.js:666:3
2018-07-03T23:32:27.960851+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-07-03T23:32:27.961370+00:00 app[web.1]: npm ERR! errno 1
2018-07-03T23:32:27.965212+00:00 app[web.1]: npm ERR! doombot#1.0.0 start: `node src/server/dist/server.js`
2018-07-03T23:32:27.966189+00:00 app[web.1]: npm ERR! Exit status 1
2018-07-03T23:32:27.967067+00:00 app[web.1]: npm ERR!
2018-07-03T23:32:27.967873+00:00 app[web.1]: npm ERR! Failed at the doombot#1.0.0 start script.
2018-07-03T23:32:27.968281+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-07-03T23:32:28.070076+00:00 heroku[web.1]: Process exited with status 1
2018-07-03T23:32:28.010680+00:00 app[web.1]:
2018-07-03T23:32:28.010886+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-07-03T23:32:28.011019+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-07-03T23_32_27_989Z-debug.log
This is my package.json file
{
"name": "doombot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"tsc": "tsc",
"start": "node src/server/dist/server.js",
"heroku-postbuild": "webpack --config webpack.prod.js; tsc -p ./tsconfig.json",
"server": "nodemon src/server/lib/server.ts",
"client": "webpack-dev-server --open --config webpack.dev.js",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"keywords": [],
"author": "",
"license": "ISC",
"engines": {
"npm": "6.0.0",
"node": "9.9.0"
},
"dependencies": {
"#types/express": "^4.11.1",
"antd": "^3.6.4",
"app-root-path": "^2.1.0",
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"express": "^4.16.3",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"typescript": "2.9.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-import": "^1.8.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"concurrently": "^3.5.1",
"css-loader": "^0.28.11",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"html-webpack-plugin": "^3.2.0",
"nodemon": "^1.17.3",
"style-loader": "^0.20.3",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.5.0",
"webpack-cli": "^2.0.14",
"webpack-dev-server": "^3.1.3",
"webpack-merge": "^4.1.3"
}
}
webpack.common.js
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/client/index.js',
plugins: [new CleanWebpackPlugin(['build']), new HtmlWebpackPlugin()],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build')
}
};
webpack.dev.js
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const path = require('path');
module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
devServer: {
contentBase: './build',
port: 3000,
open: true,
proxy: {
'/api': 'http://localhost:4040'
}
}
});
webpack.prod.js
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const path = require('path');
module.exports = merge(common, {
mode: 'production',
devtool: 'source-map',
plugins: [
new UglifyJSPlugin({
sourceMap: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
});
and my tsconfig file
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"pretty": true,
"sourceMap": true,
"target": "es6",
"outDir": "./src/server/dist", // creates the dist directory & places compiles files here
"baseUrl": "./src/server/lib"
},
"include": [
"./src/server/lib/**/*.ts" // specifies that we should include all ts files within lib
],
"exclude": ["node_modules"]
}
If I understand correctly, this is not appearing due to it not building properly. My question is how can I build and run my app the correct way?
If you would like to see my entire code, you can find it here - https://github.com/albertogodinez/dooms-data
You're missing quite a few steps. Let's backtrack a bit.
You're telling Heroku that to start your app, it should run node src/server/dist/server.js (because you specify that as the start script in your package.json). However, server.js does not exist on Heroku, there's only server.ts (i.e. the TypeScript file).
Thus, you'll have to tell Heroku to convert your TypeScript file to Javascript - right now, you're only telling it to build your client (i.e. through webpack in the heroku-postbuild script). To fix this, you can change that script to "webpack --mode production; tsc --project=tsconfig.json",
However, that won't work either as the TypeScript compiler is not installed on Heroku. Therefore, be sure to add typescript to your dependencies (note that IIRC, Heroku does not install devDependencies, so either make it a regular dependency or tell Heroku to install devDependencies as well.
Even if your server then runs correctly, it only serves your API. If you also want your client to be reachable, you have to tell Express to serve it. You could do that something like this:
.
app.use(
express.static(
path.join(__dirname, '../../compiled_frontend'),
{ index: false },
),
);
That, I think, should do the trick, but obviously more could be wrong. Coincidentally, I'm working on an app with a very similar setup, and it's open source - so feel free to give it a look if you need inspiration.

Heroku with React and nodemailer build failing

Im having issues getting my build on heroku to work. Heroku is saying the build succeeded but when I pull up the page I get the Application Error page.
Here is my package.JSON for the React
{
"name": "cloudveilheli",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"concurrently": "^3.5.1",
"express": "^4.16.3",
"firebase": "^4.8.1",
"moment": "^2.22.1",
"nodemailer": "^4.6.5",
"nodemon": "^1.17.5",
"re-base": "^3.2.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"node-sass": "^4.7.2",
"react-scripts": "1.0.17",
"redux": "^3.7.2",
"sass-loader": "^6.0.6",
"webpack": "^3.10.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
and for the node.js
{
"name": "cloudveilheli",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"concurrently": "^3.5.1",
"express": "^4.16.3",
"firebase": "^4.8.1",
"moment": "^2.22.1",
"nodemailer": "^4.6.5",
"nodemon": "^1.17.5",
"re-base": "^3.2.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"node-sass": "^4.7.2",
"react-scripts": "1.0.17",
"redux": "^3.7.2",
"sass-loader": "^6.0.6",
"webpack": "^3.10.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
In the logs, I am getting an error that react-scripts are failing in the Heroku build process. The node and the react are getting fired but it fails soon after that.
And here are the heroku logs
2018-06-13T12:56:17.879178+00:00 app[web.1]: [1] sh: 1: react-scripts: not found
2018-06-13T12:56:17.910185+00:00 app[web.1]: [1] npm ERR! file sh
2018-06-13T12:56:17.910189+00:00 app[web.1]: [1] npm ERR! code ELIFECYCLE
2018-06-13T12:56:17.912160+00:00 app[web.1]: [1] npm ERR! errno ENOENT
2018-06-13T12:56:17.913985+00:00 app[web.1]: [1] npm ERR! syscall spawn
2018-06-13T12:56:17.922554+00:00 app[web.1]: [1] npm ERR! cloudveilheli#0.1.0 start: `react-scripts start`
2018-06-13T12:56:17.927487+00:00 app[web.1]: [1] npm ERR! spawn ENOENT
2018-06-13T12:56:17.928818+00:00 app[web.1]: [1] npm ERR!
2018-06-13T12:56:17.932398+00:00 app[web.1]: [1] npm ERR! Failed at the cloudveilheli#0.1.0 start script.
2018-06-13T12:56:17.932401+00:00 app[web.1]: [1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-06-13T12:56:17.967183+00:00 app[web.1]: [1] npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2018-06-13T12:56:17.968219+00:00 app[web.1]: [1]
2018-06-13T12:56:17.968222+00:00 app[web.1]: [1] npm ERR! A complete log of this run can be found in:
2018-06-13T12:56:17.968224+00:00 app[web.1]: [1] npm ERR! /app/.npm/_logs/2018-06-13T12_56_17_935Z-debug.log
2018-06-13T12:56:17.992492+00:00 app[web.1]: [1] npm ERR! code ELIFECYCLE
2018-06-13T12:56:17.992495+00:00 app[web.1]: [1] npm ERR! errno 1
2018-06-13T12:56:17.996672+00:00 app[web.1]: [1] npm ERR! bluebirdheliapp#1.0.0 client: `npm run start --prefix cloudveil_heli_app`
2018-06-13T12:56:17.999397+00:00 app[web.1]: [1] npm ERR! Exit status 1
2018-06-13T12:56:18.004427+00:00 app[web.1]: [1] npm ERR!
2018-06-13T12:56:18.004430+00:00 app[web.1]: [1] npm ERR! Failed at the bluebirdheliapp#1.0.0 client script.
2018-06-13T12:56:18.004432+00:00 app[web.1]: [1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-06-13T12:56:18.021046+00:00 app[web.1]: [1]
2018-06-13T12:56:18.021050+00:00 app[web.1]: [1] npm ERR! A complete log of this run can be found in:
2018-06-13T12:56:18.021052+00:00 app[web.1]: [1] npm ERR! /app/.npm/_logs/2018-06-13T12_56_18_005Z-debug.log
2018-06-13T12:56:18.046560+00:00 app[web.1]: [1] npm run client exited with code 1
while you push your app to heroku
first it runs npm install
later it runs npm start
so we have to declare in package.json what to run after npm install is completed and what npm start need to do.
update you package.json with:
{
"name": "cloudveilheli",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"scripts": {
"start": "node server.js",
"postinstall": "npm start build "
},
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
where postinstall works after the npminstall is completed
and create a server.js file like this:
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/dist'));
app.all('*', (req, res) => {
res.status(200).sendFile(__dirname + '/dist/index.html');
});
app.listen(process.env.PORT || 8080);
at dist/index.html give where index.html created in react
as i dont know react

Heroku keep crashing after Starting process with command `npm start'

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"
}
}

heroku nodejs deploy errors, require modules

I have followed the instructions but it stil doesnt work. My repository is this:
https://github.com/diegoarcega/learning_react
Procfile
web: node index.js
index.js
var cool = require('cool-ascii-faces');
var express = require('express');
var path = require('path');
var app = express();
var DIST_DIR = path.resolve(__dirname + '/../dist');
app.set('port', (process.env.PORT || 5000));
app.use('/assets/', express.static(DIST_DIR + '/assets'));
app.get('/', function(req, res) {
res.send('hello');
});
app.get('/cool', function(request, response) {
response.send(cool());
});
app.listen(app.get('port'), function() {
console.log('Listening port ' + app.get('port'))
});
package.json
{
"name": "learning_react",
"version": "0.0.1",
"description": "practising react",
"main": "index.js",
"scripts": {
"kill": "fuser -k 30000/tcp",
"start": "node index.js",
"serve": "node index.js",
"dev": "NODE_ENV=development babel-node server/server.js",
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rimraf dist/ ",
"copy": "copyfiles -f src/index.html src/favicon.ico dist",
"prod": "npm run clean && webpack --config webpack.config.dist.js -p && npm run copy",
"dist": "NODE_ENV=production babel-node server/server.js ",
"deploy": "surge --project ./dist --domain diegoarcega-react.surge.sh"
},
"repository": {
"type": "git",
"url": "https://github.com/diegoarcega/learning_react"
},
"keywords": [
"REACT"
],
"engines": {
"node": "4.4.5",
"npm": "3.9.6"
},
"author": "Diego Arcega",
"license": "BSD-2-Clause",
"bugs": {
"url": "https://github.com/diegoarcega/learning_react/issues"
},
"dependencies": {
"axios": "^0.12.0",
"babel-polyfill": "^6.9.1",
"cool-ascii-faces": "^1.3.4",
"firebase": "^3.0.5",
"material-ui": "^0.15.1",
"muicss": "^0.6.5",
"q": "^1.4.1",
"react": "~15.1.0",
"react-dom": "~15.1.0",
"react-redux": "~4.4.5",
"react-router": "~2.4.1",
"react-tap-event-plugin": "^1.0.0",
"redux": "~3.5.2",
"redux-thunk": "^2.1.0"
},
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-core": "~6.9.1",
"babel-loader": "~6.2.4",
"babel-plugin-transform-es2015-function-name": "^6.9.0",
"babel-plugin-transform-es2015-literals": "^6.8.0",
"babel-plugin-transform-es2015-template-literals": "^6.8.0",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-preset-es2015": "~6.9.0",
"babel-preset-react": "~6.5.0",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-react-optimize": "^1.0.1",
"copyfiles": "^1.0.0",
"css-loader": "^0.23.1",
"express": "~4.13.4",
"file-loader": "^0.8.5",
"object-assign": "^4.1.0",
"react-css-modules": "^3.7.6",
"react-tap-event-plugin": "^1.0.0",
"react-thunk": "^1.0.0",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"webpack": "~1.13.1",
"webpack-dev-middleware": "^1.6.1",
"webpack-dev-server": "^1.14.1",
"webpack-hot-middleware": "^2.10.0"
}
}
I am just trying to make it work first. The error log is this:
2016-07-06T17:00:56.197239+00:00 heroku[web.1]: State changed from crashed to starting
2016-07-06T17:01:00.211013+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-07-06T17:01:01.580923+00:00 app[web.1]: module.js:327
2016-07-06T17:00:54.456548+00:00 heroku[api]: Deploy 23f2e63 by diegoarcega#gmail.com
2016-07-06T17:01:01.580940+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:2:15)
2016-07-06T17:01:01.580940+00:00 app[web.1]: at Module._compile (module.js:409:26)
2016-07-06T17:01:02.228107+00:00 heroku[web.1]: State changed from starting to crashed
2016-07-06T17:01:02.212126+00:00 heroku[web.1]: Process exited with status 1
2016-07-06T17:01:01.580941+00:00 app[web.1]: at Function.Module._load (module.js:300:12)
2016-07-06T17:01:01.580942+00:00 app[web.1]: at Function.Module.runMain (module.js:441:10)
2016-07-06T17:01:01.580939+00:00 app[web.1]: at Function.Module._load (module.js:276:25)
2016-07-06T17:01:01.580939+00:00 app[web.1]: at Module.require (module.js:353:17)
2016-07-06T17:01:01.580940+00:00 app[web.1]: at require (internal/module.js:12:17)
2016-07-06T17:01:01.580940+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:2:15)
2016-07-06T17:01:01.580940+00:00 app[web.1]: at Module._compile (module.js:409:26)
2016-07-06T17:01:01.580941+00:00 app[web.1]: at Object.Module._extensions..js (module.js:416:10)
2016-07-06T17:01:02.228107+00:00 heroku[web.1]: State changed from starting to crashed
2016-07-06T17:01:02.212126+00:00 heroku[web.1]: Process exited with status 1
2016-07-06T17:02:12.435185+00:00 heroku[slug-compiler]: Slug compilation started
2016-07-06T17:02:12.435194+00:00 heroku[slug-compiler]: Slug compilation finished
2016-07-06T17:02:12.782559+00:00 heroku[web.1]: State changed from crashed to starting
2016-07-06T17:02:17.345331+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-07-06T17:02:19.470185+00:00 app[web.1]: module.js:327
2016-07-06T17:02:19.470199+00:00 app[web.1]: throw err;
2016-07-06T17:02:19.470211+00:00 app[web.1]: Error: Cannot find module 'express'
2016-07-06T17:02:19.470212+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:325:15)
2016-07-06T17:02:19.470217+00:00 app[web.1]: at Function.Module._load (module.js:300:12)
2016-07-06T17:02:19.470217+00:00 app[web.1]: at Function.Module.runMain (module.js:441:10)
2016-07-06T17:02:20.579075+00:00 heroku[web.1]: Process exited with status 1
2016-07-06T17:02:20.600663+00:00 heroku[web.1]: State changed from starting to crashed
2016-07-06T17:02:12.174712+00:00 heroku[api]: Deploy 23f2e63 by diegoarcega#gmail.com
figured it out, never forget to install express in dependencies instead of devDependencies ;)

Resources