My full stack application won't run NodeJS and React concurrently - node.js

Running the client server and the backend server independently will produce no errors but mongoDB exits automatically when client and server run concurrently
npm start
[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `concurrently "npm run client" "npm run server"`
[0]
[0] > roster#0.1.0 client /Users/owner/Documents/projects/roster
[0] > react-scripts start
[0]
[1]
[1] > roster#0.1.0 server /Users/owner/Documents/projects/roster
[1] > cd src/server nodemon index.js
[1]
[1] npm run server exited with code 0
[0] ℹ 「wds」: Project is running at http://192.168.0.4/
[0] ℹ 「wds」: webpack output is served from
[0] ℹ 「wds」: Content not from webpack is served from /Users/owner/Documents/projects/roster/public
[0] ℹ 「wds」: 404s will fallback to /
[0] Starting the development server...
A snippet of my package.json. I'm running npm start from the root folder roster.
"scripts": {
"start": "concurrently \"npm run client\" \"npm run server\" ",
"server": "cd src/server nodemon index.js",
"client": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
require('dotenv').config();
const express = require('express');
const handle = require('./handlers');
const cors = require('cors');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const app = express();
app.use(bodyParser.json());
app.use(cors());
app.use(express.json());
const uri = process.env.URI;
mongoose.connect(uri, {useNewUrlParser: true, useCreateIndex: true});
const connection = mongoose.connection;
connection.once('open', () => {
console.log("MongoDB database connection established")
})
const votesRouter = require('./routes/votes')
app.use('/votes', votesRouter);
require('dotenv').config();
app.get('/', (req, res) => res.send('hello world'));
app.use(handle.notFound);
app.use(handle.errors);
app.listen(port, console.log(`Server running on port ${port}`));

Add && to your server script
"server": "cd src/server && nodemon index.js"

That is not mongoDB.
It sounds like your two servers might be trying to run on the same port. What port do each of the servers run on?
What is in the server index.js? It is exiting with error code 0, which indicates no error exit.

Related

Deploying to Heroku: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"

I am having issues deploying to Heroku. I have uploaded the relevant env variables under "Config Vars" within Heroku Dashboard but am wondering why I am still getting hit with the following error below:
2022-07-22T06:47:59.068313+00:00 heroku[web.1]: Starting process with command `npm start`
2022-07-22T06:48:00.732711+00:00 app[web.1]:
2022-07-22T06:48:00.732804+00:00 app[web.1]: > project-management-webapp#1.0.0 start
2022-07-22T06:48:00.732804+00:00 app[web.1]: > npm install && cd server && node index.js
2022-07-22T06:48:00.732805+00:00 app[web.1]:
2022-07-22T06:48:01.693914+00:00 app[web.1]:
2022-07-22T06:48:01.693932+00:00 app[web.1]: up to date, audited 128 packages in 601ms
2022-07-22T06:48:01.694072+00:00 app[web.1]:
2022-07-22T06:48:01.694106+00:00 app[web.1]: 14 packages are looking for funding
2022-07-22T06:48:01.694126+00:00 app[web.1]: run `npm fund` for details
2022-07-22T06:48:01.695406+00:00 app[web.1]:
2022-07-22T06:48:01.695406+00:00 app[web.1]: found 0 vulnerabilities
2022-07-22T06:48:02.296149+00:00 heroku[web.1]: State changed from starting to crashed
2022-07-22T06:48:02.083051+00:00 app[web.1]: Server running on port 24830
2022-07-22T06:48:02.087994+00:00 app[web.1]: /app/node_modules/mongodb-connection-string-url/lib/index.js:86
2022-07-22T06:48:02.088006+00:00 app[web.1]: throw new MongoParseError('Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"');
2022-07-22T06:48:02.088007+00:00 app[web.1]: ^
2022-07-22T06:48:02.088007+00:00 app[web.1]:
2022-07-22T06:48:02.088013+00:00 app[web.1]: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
2022-07-22T06:48:02.088013+00:00 app[web.1]: at new ConnectionString (/app/node_modules/mongodb-connection-string-url/lib/index.js:86:19)
2022-07-22T06:48:02.088014+00:00 app[web.1]: at parseOptions (/app/node_modules/mongodb/lib/connection_string.js:209:17)
2022-07-22T06:48:02.088014+00:00 app[web.1]: at new MongoClient (/app/node_modules/mongodb/lib/mongo_client.js:62:63)
2022-07-22T06:48:02.088015+00:00 app[web.1]: at /app/node_modules/mongoose/lib/connection.js:796:16
2022-07-22T06:48:02.088015+00:00 app[web.1]: at new Promise (<anonymous>)
2022-07-22T06:48:02.088016+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:793:19)
2022-07-22T06:48:02.088016+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:379:10
2022-07-22T06:48:02.088016+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
2022-07-22T06:48:02.088016+00:00 app[web.1]: at new Promise (<anonymous>)
2022-07-22T06:48:02.088021+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
2022-07-22T06:48:02.228355+00:00 heroku[web.1]: Process exited with status 1
Below is the relevant code:
INDEX.JS
const express = require('express')
const colors = require('colors')
const { graphqlHTTP } = require('express-graphql')
const cors = require('cors')
const schema = require('./schema/schema')
const connectDB = require('./config/db')
require('dotenv').config()
const app = express()
// MongoDB
connectDB()
// CORS
app.use(cors())
// GraphQL
app.use(
'/graphql',
graphqlHTTP({
schema: schema,
graphiql: process.env.NODE_ENV === 'development',
})
)
app.listen(
process.env.PORT || 4000,
console.log(`Server running on port ${process.env.PORT}`)
)
DB.JS
const mongoose = require('mongoose')
const connectDB = async () => {
const conn = await mongoose.connect(process.env.MONGODB_URI)
console.log(`MongoDB Connected: ${conn.connection.host}`.cyan.underline.bold)
}
module.exports = connectDB
PACKAGE.JSON
{
"name": "project-management-webapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "npm install && cd server && node index.js",
"dev": "nodemon server/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/BIGWALDOR/project-management-webapp.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/BIGWALDOR/project-management-webapp/issues"
},
"homepage": "https://github.com/BIGWALDOR/project-management-webapp#readme",
"dependencies": {
"colors": "^1.4.0",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"express-graphql": "^0.12.0",
"graphql": "^15.8.0",
"mongoose": "^6.4.5"
},
"devDependencies": {
"nodemon": "^2.0.19"
}
}
I'm definitely at a loss here so any help would be much appreciated!

querySrv ENOTFOUND _mongodb._tcp.cluster0-lmapeno.mongodb.net

i'm trying to run this airbnb clone: https://github.com/ricardovasconcelos/AirbnbClone made with react, node, socket.io and mongodb, when it comes to frontend, it runs perfectly, but I'm having an error when trying to run the backend.
This is my package.json:
{
"name": "backend",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev": "nodemon src/server.js",
"start": "nodemon src/server.js"
},
"license": "MIT",
"devDependencies": {
"nodemon": "^1.19.4"
},
"dependencies": {
"colors": "^1.4.0",
"cors": "^2.8.5",
"express": "^4.17.3",
"mongoose": "^5.7.3",
"multer": "^1.4.2",
"socket.io": "^2.4.1",
"socket.io-client": "^4.4.1"
}
}
This is my database.js:
const mongoose = require('mongoose')
mongoose.connect('mongodb+srv://airbnb:airbnb#cluster0-lmape.mongodb.net/airbnbClone?retryWrites=true&w=majority', {
useNewUrlParser:true,
useUnifiedTopology: true
})
This is my server.js:
const express = require('express')
const routes = require('./routes')
const cors = require('cors')
const path = require('path')
const socketio = require('socket.io')
const http = require('http')
require('./database/database')
const server = express()
const app = http.Server(server)
const io = socketio(app)
const connectedUsers = {}
io.on('connection', socket => {
const { user_id } = socket.handshake.query
connectedUsers[user_id] = socket.id
})
server.use((req,res,next) => {
req.io = io
req.connectedUsers = connectedUsers
return next()
})
server.use(cors())
server.use(express.json())
server.use('/files', express.static(path.resolve(__dirname, '..','uploads')))
server.use(routes)
app.listen(3333, ()=>console.log('running on 3333'))
This error appears:
$ nodemon src/server.js
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src/server.js`
(node:59368) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:59368) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
(node:59368) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
(node:59368) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
running on 3333
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error: querySrv ENOTFOUND _mongodb._tcp.cluster0-lmape.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (node:dns:213:19) {
errno: undefined,
code: 'ENOTFOUND',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0-lmape.mongodb.net'
}
[nodemon] app crashed - waiting for file changes before starting...
I have installed all the dependencies, I would appreciate if someone can help me.
Thanks

Problem with React/Node.js app deployment on Heroku

I have problem with deployment of my 'TODO APP' on Heroku. I read multiple articles, tutorials and answers on Stack Overflow, but it still doesn't resolve my problem.
This is my index.js file in root directory:
const express = require('express')
const apiRoute = require('./routes/api/index')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true
}))
app.use('/api', apiRoute)
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'))
const path = require('path')
app.get('*', function(req, res) {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})
}
const PORT = process.env.PORT || 8000
app.listen(PORT)
In the code below you can see scripts in package.json for root directory:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"client": "npm run start --prefix client",
"server": "nodemon index.js",
"dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
"start": "node index.js",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
In the heroku logs I can see, that "concurrently is not found:
2020-05-18T19:00:50.438389+00:00 app[web.1]: sh: 1: concurrently: not found
2020-05-18T19:00:50.443535+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-18T19:00:50.444083+00:00 app[web.1]: npm ERR! syscall spawn
2020-05-18T19:00:50.444495+00:00 app[web.1]: npm ERR! file sh
2020-05-18T19:00:50.444972+00:00 app[web.1]: npm ERR! errno ENOENT
2020-05-18T19:00:50.446708+00:00 app[web.1]: npm ERR! to-do-app#1.0.0 start: `concurrently "npm run server" "npm run client"`
2020-05-18T19:00:50.446990+00:00 app[web.1]: npm ERR! spawn ENOENT
I have tried multiple things, but none of them work. Any ideas please?
In your package.json maybe the script dev is causing an issue.
Try clearing all the scripts and only leave
"start" : "node server.js"
"test": "echo "Error: no test specified" && exit 1"
"heroku-postbuild": "cd client && npm install && npm run build"

My node + express app deploys fine locally but will not deploy when pushed to heroku

first off my apologies if this is a basic solve. I'm new to Node + Express and still trying to grapple a few concepts!
I have a Node + Express app that starts locally but when I push to heroku or run heroku local web it exits with code 0 and produces no error code for me to diagnose.
Here is the specific output from the logs when I deploy to Heroku:
2018-06-30T11:58:37.052754+00:00 heroku[web.1]: Starting process with command `npm run build`
2018-06-30T11:58:39.336703+00:00 app[web.1]:
2018-06-30T11:58:39.336728+00:00 app[web.1]: > bookworm-api#1.0.0 build /app
2018-06-30T11:58:39.336733+00:00 app[web.1]: > npm run clean && npm run build-babel
2018-06-30T11:58:39.336734+00:00 app[web.1]:
2018-06-30T11:58:39.777160+00:00 app[web.1]:
2018-06-30T11:58:39.777199+00:00 app[web.1]: > bookworm-api#1.0.0 clean /app
2018-06-30T11:58:39.777201+00:00 app[web.1]: > rm -rf build && mkdir build
2018-06-30T11:58:39.777202+00:00 app[web.1]:
2018-06-30T11:58:40.305583+00:00 app[web.1]:
2018-06-30T11:58:40.305603+00:00 app[web.1]: > bookworm-api#1.0.0 build-babel /app
2018-06-30T11:58:40.305605+00:00 app[web.1]: > babel -d ./build ./src -s
2018-06-30T11:58:40.305610+00:00 app[web.1]:
2018-06-30T11:58:41.146122+00:00 app[web.1]: src/index.js -> build/index.js
2018-06-30T11:58:41.196474+00:00 app[web.1]: src/mailer.js -> build/mailer.js
2018-06-30T11:58:41.242714+00:00 app[web.1]: src/models/Circuit.js -> build/models/Circuit.js
2018-06-30T11:58:41.293304+00:00 app[web.1]: src/models/User.js -> build/models/User.js
2018-06-30T11:58:41.346985+00:00 app[web.1]: src/routes/auth.js -> build/routes/auth.js
2018-06-30T11:58:41.362022+00:00 app[web.1]: src/routes/circuits.js -> build/routes/circuits.js
2018-06-30T11:58:41.380720+00:00 app[web.1]: src/routes/stripe.js -> build/routes/stripe.js
2018-06-30T11:58:41.411474+00:00 app[web.1]: src/routes/users.js -> build/routes/users.js
2018-06-30T11:58:41.423692+00:00 app[web.1]: src/utils/parseErrors.js -> build/utils/parseErrors.js
2018-06-30T11:58:41.508066+00:00 heroku[web.1]: Process exited with status 0
2018-06-30T11:58:41.532442+00:00 heroku[web.1]: State changed from starting to crashed
Here is the output when I run Heroku local web
[OKAY] Loaded ENV .env File as KEY=VALUE Format
8:04:38 AM web.1 | > bookworm-api#1.0.0 build /Users/kylependergast/Desktop/projects/bookworm/bookworm-api
8:04:38 AM web.1 | > npm run clean && npm run build-babel
8:04:38 AM web.1 | > bookworm-api#1.0.0 clean /Users/kylependergast/Desktop/projects/bookworm/bookworm-api
8:04:38 AM web.1 | > rm -rf build && mkdir build
8:04:39 AM web.1 | > bookworm-api#1.0.0 build-babel /Users/kylependergast/Desktop/projects/bookworm/bookworm-api
8:04:39 AM web.1 | > babel -d ./build ./src -s
8:04:39 AM web.1 | src/index.js -> build/index.js
8:04:39 AM web.1 | src/mailer.js -> build/mailer.js
8:04:39 AM web.1 | src/models/Circuit.js -> build/models/Circuit.js
8:04:39 AM web.1 | src/models/User.js -> build/models/User.js
8:04:39 AM web.1 | src/routes/auth.js -> build/routes/auth.js
8:04:39 AM web.1 | src/routes/circuits.js -> build/routes/circuits.js
8:04:39 AM web.1 | src/routes/stripe.js -> build/routes/stripe.js
8:04:39 AM web.1 | src/routes/users.js -> build/routes/users.js
8:04:39 AM web.1 | src/utils/parseErrors.js -> build/utils/parseErrors.js
8:04:39 AM web.1 Exited Successfully
Here is my package.json file:
{
"name": "bookworm-api",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "nodemon --exec babel-node -- src/index.js",
"clean": "rm -rf build && mkdir build",
"build-babel": "babel -d ./build ./src -s",
"build": "npm run clean && npm run build-babel",
"start": "npm run build && node ./build/index.js"
},
"engines": {
"node": "9.4.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^8.2.3",
"babel-preset-env": "^1.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-prettier": "^2.6.0",
"nodemon": "^1.17.4"
},
"dependencies": {
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"bcrypt": "^2.0.1",
"bluebird": "^3.5.1",
"body-parser": "^1.18.2",
"dotenv": "^5.0.1",
"express": "^4.16.3",
"jsonwebtoken": "^8.2.1",
"lodash": "^4.17.10",
"mongodb": "^3.1.0",
"mongoose": "^4.11.10",
"mongoose-unique-validator": "^2.0.1",
"nodemailer": "^4.6.4",
"request-promise": "^4.2.2",
"stripe": "^6.1.1",
"uuid": "^3.2.1",
"xml2js": "^0.4.19"
}
}
And here is my index.js file:
import express from 'express';
import path from 'path';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
import Promise from 'bluebird';
import auth from './routes/auth';
import users from './routes/users';
import circuits from "./routes/circuits";
import stripe from './routes/stripe';
dotenv.config();
const app = express();
app.use(bodyParser.json());
mongoose.Promise = Promise;
mongoose.connect(
process.env.MONGODB_URI || process.env.MONGODB_URL_DEV_LOCAL,
{useMongoClient: true});
app.use('/api/auth', auth);
app.use('/api/users', users);
app.use('/api/circuits', circuits);
app.use('/api/stripe', stripe);
app.post('/api/auth', (req, res) => {
res.status(400).json({ errors: {global: "Invalid Credentials" } });
});
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
})
var port = process.env.PORT || 8080
app.listen(port || 8080, function(){
console.log("App is running on port " + port);
});
Here is my Procfile
web: npm run build
I'm sure someone else has run into this issue but I've been unable to find resources that suggest what next steps to take. If you can point me to a relevant resource or provide the answer yourself it would be very much appreciated!
Your Procfile seems to be defined such that you're building stuff when starting the process. The build succeeds (returns 0), but then the process stops, which Heroku thinks is a bad condition, cause web servers shouldn't stop.
You need to actually run the web server in Heroku. Something like web: npm run start.
Though I would separate the build & run stages. You should do the build locally, or on a build machine (or a build service, such as Travis, Circle etc - they have Heroku integrations as well), and then push something compiled to Heroku. So Procfile could only be web: node ./build/index.js or something like that.

ExpressJS / Heroku Application Error

I am attempting to deploy a test express app on Heroku.
My package.json looks like this -
{
"name": "heroku-test-app",
"version": "1.0.0",
"description": "",
"main": "dist",
"scripts": {
"test": "cross-env NODE_ENV=test nodemon --exec mocha ./**/*.spec.js --compilers js:babel-core/register --require babel-polyfill",
"dev": "nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"",
"build": "babel src -s -D -d dist --presets es2015,stage-0",
"start": "cross-env node dist",
"prestart": "npm run -s build",
"clean": "rimraf dist/"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"body-parser": "^1.17.2",
"cross-env": "^5.0.5",
"dotenv": "^4.0.0",
"express": "^4.15.4",
"morgan": "^1.8.2"
},
"devDependencies": {
"chai": "^4.1.1",
"mocha": "^3.5.0",
"nodemon": "^1.11.0",
"rimraf": "^2.6.1",
"supertest": "^3.0.0"
}
}
My Procfile looks like this -
web: npm start
and my test app is as so -
import express from 'express';
import morgan from 'morgan';
import bodyParser from 'body-parser';
const app = express();
const postBodyLimit = '100kb';
const port = 3000;
app.use(
morgan('combined', {
skip: (req, res) => res.statusCode < 400
})
);
app.use(bodyParser.json({ limit: postBodyLimit }));
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', (req, res) => res.status(200).json({ message: 'No unicorns here.' }));
// catch 404's and pass to our global error handler
app.all('*', (req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use((err, req, res, next) => {
res.status(err.status || 500).json({
message: err.message,
error: app.get('env') === 'development' ? err : null
});
});
app.listen(port, () => console.log(`listening on port ${port}`));
export default app;
When running my app locally, it starts and works perfectly. When running heroku local web, it also works as expected.
When I deploy to heroku however, I get the application error page. However on streaming my logs, there is nothing to suggest it has crashed.
I have just deployed again now, this is the current log file
2017-08-28T06:38:40.000000+00:00 app[api]: Build succeeded
2017-08-28T06:39:03.959631+00:00 app[web.1]:
2017-08-28T06:39:03.959649+00:00 app[web.1]: > heroic-test-app#1.0.0 prestart /app
2017-08-28T06:39:03.959650+00:00 app[web.1]: > npm run -s build
2017-08-28T06:39:03.959651+00:00 app[web.1]:
2017-08-28T06:39:05.856118+00:00 app[web.1]: src/index.js -> dist/index.js
2017-08-28T06:39:05.898228+00:00 app[web.1]:
2017-08-28T06:39:05.898232+00:00 app[web.1]: > heroic-test-app#1.0.0 start /app
2017-08-28T06:39:05.898234+00:00 app[web.1]: > cross-env node dist
2017-08-28T06:39:05.898234+00:00 app[web.1]:
2017-08-28T06:39:06.654100+00:00 app[web.1]: listening on port 3000
2017-08-28T06:44:40.078283+00:00 app[web.1]:
2017-08-28T06:44:40.078319+00:00 app[web.1]: > heroic-test-app#1.0.0 prestart /app
2017-08-28T06:44:40.078320+00:00 app[web.1]: > npm run -s build
2017-08-28T06:44:40.078321+00:00 app[web.1]:
2017-08-28T06:44:42.379605+00:00 app[web.1]: src/index.js -> dist/index.js
2017-08-28T06:44:42.434704+00:00 app[web.1]:
2017-08-28T06:44:42.434707+00:00 app[web.1]: > heroic-test-app#1.0.0 start /app
2017-08-28T06:44:42.434708+00:00 app[web.1]: > cross-env node dist
2017-08-28T06:44:42.434709+00:00 app[web.1]:
2017-08-28T06:44:43.156940+00:00 app[web.1]: listening on port 3000
2017-08-28T06:45:39.332668+00:00 app[web.1]: Error waiting for process to terminate: No child processes
I am at a loss how to proceed at this point.
you shouldn't set the port of http server as 3000, you should use the port of process.env, heroku will set an PORT in process.env.
So you should use app.listen(process.env.PORT, () => {}).
and there is an err code about the heroku application, if you can provide that, it would be better.

Resources