const express = require ('express');
const bodyParser = require('body-parser');
var passwordHash = require('password-hash');
const cors = require('cors');
var knex = require('knex');
const register = require('./controllers/Register');
const signin = require('./controllers/Signin');
const profile = require('./controllers/Profile');
const image = require('./controllers/Image');
//var connectionString = "postgres://*USERNAME*:*PASSWORD*#*HOST*:*PORT*/*DATABASE*"
const db = knex({
client: 'pg',
connection: {
connectionString: process.env.DATABASE_URL,
ssl: true,
}
})
const app=express();
app.use(bodyParser.json());
app.use(cors());
app.get('/',(req, res)=>{
res.send("it is working")
})
app.post('/signin',(req,res)=>{signin.handleSignIn(req,res,db,passwordHash)})
app.post('/register',(req, res)=>{register.handleRegister(req, res, db,passwordHash)})
app.get('/profile/:id', (req,res)=>{profile.handleProfileGet(req,res,db)})
app.put('/image',(req,res)=>{image.handleImage(req,res,db)})
app.post('/imageurl',(req,res)=>{image.handleApiCall(req,res)})
app.listen(process.env.PORT || 3000, ()=>{
console.log(`app is running on port ${process.env.PORT}`)
})
This is my server.js file
unable to figure out error I added all the changes using git add then used git commit -m "changed port" git push heroku master
git logs --tail (getting error here)
rohit#rohit-Vostro-3583:~/Desktop/smartbrainAPI$ heroku logs --tail
2020-04-19T11:38:00.460877+00:00 heroku[web.1]: State changed from crashed to starting
2020-04-19T11:38:04.722372+00:00 app[web.1]:
2020-04-19T11:38:04.722404+00:00 app[web.1]: > node#1.0.0 start /app
2020-04-19T11:38:04.722404+00:00 app[web.1]: > node server.js
2020-04-19T11:38:04.722405+00:00 app[web.1]:
2020-04-19T11:38:05.064464+00:00 app[web.1]: /app/server.js:21
2020-04-19T11:38:05.064499+00:00 app[web.1]: db.connect();
2020-04-19T11:38:05.064500+00:00 app[web.1]: ^
2020-04-19T11:38:05.064500+00:00 app[web.1]:
2020-04-19T11:38:05.064504+00:00 app[web.1]: TypeError: db.connect is not a function
2020-04-19T11:38:05.064505+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:21:6)
2020-04-19T11:38:05.064506+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1156:30)
2020-04-19T11:38:05.064506+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
2020-04-19T11:38:05.064506+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1000:32)
2020-04-19T11:38:05.064507+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:899:14)
2020-04-19T11:38:05.064507+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
2020-04-19T11:38:05.064508+00:00 app[web.1]: at internal/main/run_main_module.js:18:47
2020-04-19T11:38:05.070768+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-04-19T11:38:05.071050+00:00 app[web.1]: npm ERR! errno 1
2020-04-19T11:38:05.072100+00:00 app[web.1]: npm ERR! node#1.0.0 start: `node server.js`
2020-04-19T11:38:05.072245+00:00 app[web.1]: npm ERR! Exit status 1
2020-04-19T11:38:05.072422+00:00 app[web.1]: npm ERR!
2020-04-19T11:38:05.072557+00:00 app[web.1]: npm ERR! Failed at the node#1.0.0 start script.
2020-04-19T11:38:05.072688+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-04-19T11:38:05.077328+00:00 app[web.1]:
2020-04-19T11:38:05.077531+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-04-19T11:38:05.077662+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-04-19T11_38_05_073Z-debug.log
2020-04-19T11:38:05.151564+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-19T11:39:03.000000+00:00 app[api]: Build started by user rohitjain991100#gmail.com
2020-04-19T11:39:26.226816+00:00 app[api]: Deploy cf844469 by user rohitjain991100#gmail.com
2020-04-19T11:39:26.226816+00:00 app[api]: Release v20 created by user rohitjain991100#gmail.com
2020-04-19T11:39:26.932529+00:00 heroku[web.1]: State changed from crashed to starting
2020-04-19T11:39:27.000000+00:00 app[api]: Build succeeded
2020-04-19T11:39:34.492601+00:00 app[web.1]:
2020-04-19T11:39:34.492681+00:00 app[web.1]: > node#1.0.0 start /app
2020-04-19T11:39:34.492682+00:00 app[web.1]: > node server.js
2020-04-19T11:39:34.492683+00:00 app[web.1]:
2020-04-19T11:39:35.127798+00:00 heroku[web.1]: State changed from starting to up
2020-04-19T11:39:35.085705+00:00 app[web.1]: app is running on port 31626
2020-04-19T11:53:00.000000+00:00 app[api]: Build started by user rohitjain991100#gmail.com
2020-04-19T11:53:22.454500+00:00 heroku[web.1]: Restarting
2020-04-19T11:53:22.458236+00:00 heroku[web.1]: State changed from up to starting
2020-04-19T11:53:22.256081+00:00 app[api]: Release v21 created by user rohitjain991100#gmail.com
2020-04-19T11:53:22.256081+00:00 app[api]: Deploy 5c8d0f48 by user rohitjain991100#gmail.com
2020-04-19T11:53:23.000000+00:00 app[api]: Build succeeded
2020-04-19T11:53:27.273472+00:00 app[web.1]:
2020-04-19T11:53:27.273493+00:00 app[web.1]: > node#1.0.0 start /app
2020-04-19T11:53:27.273493+00:00 app[web.1]: > node server.js
2020-04-19T11:53:27.273493+00:00 app[web.1]:
2020-04-19T11:53:27.734584+00:00 heroku[web.1]: State changed from starting to up
2020-04-19T11:53:27.649117+00:00 app[web.1]: app is running on port 30116
2020-04-19T11:53:47.570119+00:00 heroku[router]: at=info method=GET path="/" host=warm-reef-38212.herokuapp.com request_id=3624d2fe-2e3a-4e0c-99d0-3f06882d864c fwd="157.39.217.175" dyno=web.1 connect=3ms service=12ms status=304 bytes=181 protocol=https
2020-04-19T11:54:51.279964+00:00 heroku[router]: at=info method=OPTIONS path="/" host=warm-reef-38212.herokuapp.com request_id=2ee65713-56e6-45b2-ba85-8d5aac800275 fwd="157.39.217.175" dyno=web.1 connect=1ms service=3ms status=204 bytes=301 protocol=https
2020-04-19T11:59:28.292870+00:00 heroku[router]: at=info method=OPTIONS path="/register" host=warm-reef-38212.herokuapp.com request_id=ef749eda-243d-4d3f-aedd-92c995701359 fwd="157.39.217.175" dyno=web.1 connect=1ms service=2ms status=204 bytes=301 protocol=https
2020-04-19T11:59:32.895743+00:00 heroku[router]: at=info method=OPTIONS path="/signin" host=warm-reef-38212.herokuapp.com request_id=34278a55-19f1-4ee1-9eae-0d9d60e0a6bc fwd="157.39.217.175" dyno=web.1 connect=1ms service=4ms status=204 bytes=301 protocol=https
2020-04-19T11:59:33.562086+00:00 heroku[router]: at=info method=POST path="/signin" host=warm-reef-38212.herokuapp.com request_id=2087a4b7-1701-4c2c-91de-3ee3085e861d fwd="157.39.217.175" dyno=web.1 connect=1ms service=41ms status=400 bytes=267 protocol=https
2020-04-19T11:59:33.878990+00:00 heroku[router]: at=info method=POST path="/signin" host=warm-reef-38212.herokuapp.com request_id=b47adc7b-6c48-4d42-b69f-12544286a6d4 fwd="157.39.217.175" dyno=web.1 connect=0ms service=16ms status=400 bytes=267 protocol=https
2020-04-19T11:59:34.454755+00:00 heroku[router]: at=info method=POST path="/signin" host=warm-reef-38212.herokuapp.com request_id=518c21f9-5d5f-4860-b2a8-e48c84096f8e fwd="157.39.217.175" dyno=web.1 connect=0ms service=11ms status=400 bytes=267 protocol=https
2020-04-19T11:59:34.565367+00:00 heroku[router]: at=info method=POST path="/signin" host=warm-reef-38212.herokuapp.com request_id=f63998c3-7850-435c-85d2-efbbde3040ef fwd="157.39.217.175" dyno=web.1 connect=2ms service=14ms status=400 bytes=267 protocol=https
2020-04-19T11:59:34.871204+00:00 heroku[router]: at=info method=POST path="/signin" host=warm-reef-38212.herokuapp.com request_id=a2322ada-8faf-4964-b5ea-76c68bba69b7 fwd="157.39.217.175" dyno=web.1 connect=1ms service=23ms status=400 bytes=267 protocol=https
2020-04-19T11:59:34.992259+00:00 heroku[router]: at=info method=POST path="/signin" host=warm-reef-38212.herokuapp.com request_id=7e896a02-2d8f-4713-99fb-26ae2bb01a02 fwd="157.39.217.175" dyno=web.1 connect=1ms service=10ms status=400 bytes=267 protocol=https
2020-04-19T12:31:42.742729+00:00 heroku[web.1]: Idling
2020-04-19T12:31:42.746564+00:00 heroku[web.1]: State changed from up to down
2020-04-20T03:36:37.247697+00:00 heroku[web.1]: Unidling
2020-04-20T03:36:37.262797+00:00 heroku[web.1]: State changed from down to starting
2020-04-20T03:36:42.828317+00:00 app[web.1]:
2020-04-20T03:36:42.828354+00:00 app[web.1]: > node#1.0.0 start /app
2020-04-20T03:36:42.828355+00:00 app[web.1]: > node server.js
2020-04-20T03:36:42.828355+00:00 app[web.1]:
2020-04-20T03:36:43.203099+00:00 app[web.1]: app is running on port 11796
2020-04-20T03:36:43.849848+00:00 heroku[web.1]: State changed from starting to up
2020-04-20T03:36:45.324642+00:00 heroku[router]: at=info method=GET path="/" host=warm-reef-38212.herokuapp.com request_id=40c07246-2b5b-4079-bda3-04b6347c2290 fwd="157.39.3.225" dyno=web.1 connect=0ms service=13ms status=304 bytes=181 protocol=https
2020-04-20T03:36:45.998463+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=warm-reef-38212.herokuapp.com request_id=e3b41154-ef4f-4823-833f-74a8dc7b29c2 fwd="157.39.3.225" dyno=web.1 connect=0ms service=6ms status=404 bytes=426 protocol=https
2020-04-20T03:54:04.000000+00:00 app[api]: Build started by user rohitjain991100#gmail.com
2020-04-20T03:54:26.193272+00:00 app[api]: Deploy 1da13236 by user rohitjain991100#gmail.com
2020-04-20T03:54:26.193272+00:00 app[api]: Release v22 created by user rohitjain991100#gmail.com
2020-04-20T03:54:27.082771+00:00 heroku[web.1]: Restarting
2020-04-20T03:54:27.096340+00:00 heroku[web.1]: State changed from up to starting
2020-04-20T03:54:27.000000+00:00 app[api]: Build succeeded
2020-04-20T03:54:31.467317+00:00 app[web.1]:
2020-04-20T03:54:31.467339+00:00 app[web.1]: > node#1.0.0 start /app
2020-04-20T03:54:31.467340+00:00 app[web.1]: > node server.js
2020-04-20T03:54:31.467340+00:00 app[web.1]:
2020-04-20T03:54:31.978215+00:00 heroku[web.1]: State changed from starting to up
2020-04-20T03:54:31.771327+00:00 app[web.1]: app is running on port 36319
2020-04-20T03:57:17.192518+00:00 heroku[router]: at=info method=OPTIONS path="/register" host=warm-reef-38212.herokuapp.com request_id=5854e26c-7119-4abc-bdd5-b398b8f051d0 fwd="157.39.119.21" dyno=web.1 connect=1ms service=9ms status=204 bytes=301 protocol=https
2020-04-20T03:57:17.634127+00:00 heroku[router]: at=info method=OPTIONS path="/signin" host=warm-reef-38212.herokuapp.com request_id=9bbc745e-1e7f-47c6-90d9-08e1aac92589 fwd="157.39.3.225" dyno=web.1 connect=1ms service=2ms status=204 bytes=301 protocol=https
2020-04-20T03:57:19.675739+00:00 heroku[router]: at=info method=POST path="/signin" host=warm-reef-38212.herokuapp.com request_id=8108baef-41d0-4b0c-a5dc-3967fe2098e4 fwd="157.39.3.225" dyno=web.1 connect=1ms service=24ms status=400 bytes=267 protocol=https
2020-04-20T04:18:31.000000+00:00 app[api]: Build started by user rohitjain991100#gmail.com
2020-04-20T04:18:52.526320+00:00 app[api]: Deploy 1c1b07e7 by user rohitjain991100#gmail.com
2020-04-20T04:18:52.526320+00:00 app[api]: Release v23 created by user rohitjain991100#gmail.com
2020-04-20T04:18:53.554662+00:00 heroku[web.1]: Restarting
2020-04-20T04:18:53.558703+00:00 heroku[web.1]: State changed from up to starting
2020-04-20T04:18:53.000000+00:00 app[api]: Build succeeded
2020-04-20T04:18:57.947008+00:00 app[web.1]:
2020-04-20T04:18:57.947025+00:00 app[web.1]: > node#1.0.0 start /app
2020-04-20T04:18:57.947026+00:00 app[web.1]: > node server.js
2020-04-20T04:18:57.947026+00:00 app[web.1]:
2020-04-20T04:18:58.227322+00:00 app[web.1]: app is running on port 12966
2020-04-20T04:18:58.560135+00:00 heroku[web.1]: State changed from starting to up
^C
rohit#rohit-Vostro-3583:~/Desktop/smartbrainAPI$ heroku pg:info
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 12.2
Created: 2020-04-19 08:42 UTC
Data Size: 8.3 MB
Tables: 2
Rows: 1/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Cont
<!-- begin snippet: js hide: false console: true babel: false -->
This is what error I am getting This is showing that i have database also for it
Help me in finding out what to change
I ahve done git add .
git commit
git push heroku master
Heroku open is also working finely
Dont know what error is
{
"name": "node",
"version": "1.0.0",
"description": "no",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"start:dev": "nodemon server.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.3"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.19.0",
"clarifai": "^2.9.1",
"cors": "^2.8.5",
"express": "^4.17.1",
"knex": "^0.20.13",
"password-hash": "^1.2.2",
"pg": "^8.0.1",
"serve": "^11.3.0"
}
}
This is my package.json file
Related
When running heroku --tail logs I get the following error response :
error:
2022-01-25T19:10:06.153750+00:00 app[web.1]: at emitErrorCloseNT (node:internal/streams/destroy:122:3)
2022-01-25T19:10:06.153750+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:83:21) {
2022-01-25T19:10:06.153751+00:00 app[web.1]: parent: Error: connect ECONNREFUSED 127.0.0.1:5432
2022-01-25T19:10:06.153751+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
2022-01-25T19:10:06.153751+00:00 app[web.1]: errno: -111,
2022-01-25T19:10:06.153751+00:00 app[web.1]: code: 'ECONNREFUSED',
2022-01-25T19:10:06.153751+00:00 app[web.1]: syscall: 'connect',
2022-01-25T19:10:06.153751+00:00 app[web.1]: address: '127.0.0.1',
2022-01-25T19:10:06.153752+00:00 app[web.1]: port: 5432
2022-01-25T19:10:06.153752+00:00 app[web.1]: },
2022-01-25T19:10:06.153752+00:00 app[web.1]: original: Error: connect ECONNREFUSED 127.0.0.1:5432
2022-01-25T19:10:06.153753+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
2022-01-25T19:10:06.153753+00:00 app[web.1]: errno: -111,
2022-01-25T19:10:06.153753+00:00 app[web.1]: code: 'ECONNREFUSED',
2022-01-25T19:10:06.153753+00:00 app[web.1]: syscall: 'connect',
2022-01-25T19:10:06.153753+00:00 app[web.1]: address: '127.0.0.1',
2022-01-25T19:10:06.153753+00:00 app[web.1]: port: 5432
2022-01-25T19:10:06.153754+00:00 app[web.1]: }
2022-01-25T19:10:06.153754+00:00 app[web.1]: }
2022-01-25T19:10:06.157055+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/novousuario" host=penedocrud.herokuapp.com request_id=c3ebdbb3-6831-493f-b8f1-8b02b051b0fd fwd="186.194.175.39" dyno=web.1 connect=0ms service=39ms status=503 bytes=0 protocol=https
2022-01-25T19:10:06.285294+00:00 heroku[web.1]: Process exited with status 1
2022-01-25T19:10:06.378171+00:00 heroku[web.1]: State changed from up to crashed
2022-01-25T19:10:06.394935+00:00 heroku[web.1]: State changed from crashed to starting
2022-01-25T19:10:08.964699+00:00 heroku[web.1]: Starting process with command `npm start`
2022-01-25T19:10:10.224154+00:00 app[web.1]:
2022-01-25T19:10:10.224168+00:00 app[web.1]: > crud-tsnode#1.0.0 start
2022-01-25T19:10:10.224168+00:00 app[web.1]: > node dist/server.js
2022-01-25T19:10:10.224169+00:00 app[web.1]:
2022-01-25T19:10:10.850373+00:00 heroku[web.1]: State changed from starting to up
2022-01-25T19:14:21.409016+00:00 heroku[router]: at=info method=GET path="/" host=penedocrud.herokuapp.com request_id=d43d2faa-2dc7-4ccd-b0b0-6953fb887da1 fwd="177.223.108.63" dyno=web.1 connect=0ms service=16ms status=302 bytes=258 protocol=https
2022-01-25T19:14:21.565056+00:00 heroku[router]: at=info method=GET path="/cadastro" host=penedocrud.herokuapp.com request_id=631aaea8-c6eb-40b9-88d4-7443f498b302 fwd="177.223.108.63" dyno=web.1 connect=0ms service=14ms status=200 bytes=2021 protocol=https
2022-01-25T19:14:21.764188+00:00 heroku[router]: at=info method=GET path="/css/home.css" host=penedocrud.herokuapp.com request_id=ab9ebd5f-dc2e-49ae-af5f-7341971cd7ce fwd="177.223.108.63" dyno=web.1 connect=0ms service=5ms status=200 bytes=4576 protocol=https
2022-01-25T19:14:21.767993+00:00 heroku[router]: at=info method=GET path="/css/user.css" host=penedocrud.herokuapp.com request_id=733a9bbc-1ed0-44aa-9707-d0f92078c8eb fwd="177.223.108.63" dyno=web.1 connect=0ms service=6ms status=200 bytes=2997 protocol=https
2022-01-25T19:14:22.539670+00:00 heroku[router]: at=info method=GET path="/images/bcg.png" host=penedocrud.herokuapp.com request_id=11255b2d-cbc6-4dfe-a1e0-6c800951e32d fwd="177.223.108.63" dyno=web.1 connect=0ms service=5ms status=200 bytes=235792 protocol=https
2022-01-25T19:14:22.542372+00:00 heroku[router]: at=info method=GET path="/images/email.png" host=penedocrud.herokuapp.com request_id=bdcdd608-9f75-4f6d-a122-93c5ef6d82e5 fwd="177.223.108.63" dyno=web.1 connect=0ms service=5ms status=200 bytes=18008 protocol=https
2022-01-25T19:14:22.816037+00:00 heroku[router]: at=info method=GET path="/images/logo.png" host=penedocrud.herokuapp.com request_id=311d663c-c948-40cc-91c9-17ce7aa7911a fwd="177.223.108.63" dyno=web.1 connect=0ms service=2ms status=200 bytes=2388 protocol=https
2022-01-25T19:14:22.818541+00:00 heroku[router]: at=info method=GET path="/images/name.png" host=penedocrud.herokuapp.com request_id=d671647e-f942-4aea-a776-5832d2bee694 fwd="177.223.108.63" dyno=web.1 connect=0ms service=3ms status=200 bytes=12497 protocol=https
2022-01-25T19:14:22.825365+00:00 heroku[router]: at=info method=GET path="/images/age.png" host=penedocrud.herokuapp.com request_id=60241f72-2f73-4fe0-bd2f-952bf8f5a6d9 fwd="177.223.108.63" dyno=web.1 connect=0ms service=7ms status=200 bytes=16444 protocol=https
2022-01-25T19:49:47.981231+00:00 heroku[web.1]: Idling
2022-01-25T19:49:47.986454+00:00 heroku[web.1]: State changed from up to down
2022-01-25T19:49:50.160588+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-01-25T19:49:50.389620+00:00 heroku[web.1]: Process exited with status 143
2022-01-25T22:46:29.540970+00:00 heroku[web.1]: Unidling
2022-01-25T22:46:29.550645+00:00 heroku[web.1]: State changed from down to starting
2022-01-25T22:46:33.398737+00:00 heroku[web.1]: Starting process with command `npm start`
2022-01-25T22:46:34.700830+00:00 app[web.1]:
2022-01-25T22:46:34.700973+00:00 app[web.1]: > crud-tsnode#1.0.0 start
2022-01-25T22:46:34.700974+00:00 app[web.1]: > node dist/server.js
2022-01-25T22:46:34.700977+00:00 app[web.1]:
2022-01-25T22:46:35.247674+00:00 heroku[web.1]: State changed from starting to up
2022-01-25T22:46:36.627250+00:00 heroku[router]: at=info method=GET path="/" host=penedocrud.herokuapp.com request_id=1fec680e-4018-429b-976c-4fa723a293e8 fwd="186.194.175.39" dyno=web.1 connect=0ms service=16ms status=302 bytes=258 protocol=https
2022-01-25T22:46:36.788688+00:00 heroku[router]: at=info method=GET path="/cadastro" host=penedocrud.herokuapp.com request_id=2325bbd9-d70d-474f-8bfb-8fe51a07c60f fwd="186.194.175.39" dyno=web.1 connect=0ms service=8ms status=200 bytes=2021 protocol=https
2022-01-25T22:46:37.002494+00:00 heroku[router]: at=info method=GET path="/css/home.css" host=penedocrud.herokuapp.com request_id=c51796ed-faf1-401f-8670-3d57ee5130a2 fwd="186.194.175.39" dyno=web.1 connect=0ms service=6ms status=200 bytes=4576 protocol=https
2022-01-25T22:46:37.147871+00:00 heroku[router]: at=info method=GET path="/css/user.css" host=penedocrud.herokuapp.com request_id=d98f6cd2-064d-4dc2-84e6-a0ac83effa49 fwd="186.194.175.39" dyno=web.1 connect=0ms service=2ms status=304 bytes=237 protocol=https
2022-01-25T22:46:37.327082+00:00 heroku[router]: at=info method=GET path="/images/bcg.png" host=penedocrud.herokuapp.com request_id=e6766750-c7c3-4b5a-a9c6-c872d4af4bab fwd="186.194.175.39" dyno=web.1 connect=0ms service=5ms status=200 bytes=235792 protocol=https
2022-01-25T22:46:37.328041+00:00 heroku[router]: at=info method=GET path="/images/email.png" host=penedocrud.herokuapp.com request_id=306aceb2-9e0b-418e-b276-33479a270ad4 fwd="186.194.175.39" dyno=web.1 connect=0ms service=4ms status=200 bytes=18008 protocol=https
2022-01-25T22:46:37.582686+00:00 heroku[router]: at=info method=GET path="/images/name.png" host=penedocrud.herokuapp.com request_id=25b9cae2-fb7f-4e89-8a0b-3de030fb9391 fwd="186.194.175.39" dyno=web.1 connect=0ms service=3ms status=200 bytes=12497 protocol=https
2022-01-25T22:46:37.611328+00:00 heroku[router]: at=info method=GET path="/images/age.png" host=penedocrud.herokuapp.com request_id=912a75a1-f82a-4fea-99e0-c88eed20c88b fwd="186.194.175.39" dyno=web.1 connect=0ms service=2ms status=200 bytes=16444 protocol=https
2022-01-25T22:46:37.861955+00:00 heroku[router]: at=info method=GET path="/images/logo.png" host=penedocrud.herokuapp.com request_id=394eb964-0efa-4cc6-84e2-c1007629f51e fwd="186.194.175.39" dyno=web.1 connect=0ms service=2ms status=200 bytes=2388 protocol=https
2022-01-25T22:46:43.833799+00:00 app[web.1]: /app/node_modules/sequelize/dist/lib/dialects/postgres/connection-manager.js:130
2022-01-25T22:46:43.833826+00:00 app[web.1]: reject(new sequelizeErrors.ConnectionRefusedError(err));
2022-01-25T22:46:43.833827+00:00 app[web.1]: ^
2022-01-25T22:46:43.833827+00:00 app[web.1]:
2022-01-25T22:46:43.833827+00:00 app[web.1]: ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:5432
2022-01-25T22:46:43.833828+00:00 app[web.1]: at Client._connectionCallback (/app/node_modules/sequelize/dist/lib/dialects/postgres/connection-manager.js:130:24)
2022-01-25T22:46:43.833828+00:00 app[web.1]: at Client._handleErrorWhileConnecting (/app/node_modules/pg/lib/client.js:305:19)
2022-01-25T22:46:43.833829+00:00 app[web.1]: at Client._handleErrorEvent (/app/node_modules/pg/lib/client.js:315:19)
2022-01-25T22:46:43.833829+00:00 app[web.1]: at Connection.emit (node:events:390:28)
2022-01-25T22:46:43.833830+00:00 app[web.1]: at Socket.reportStreamError (/app/node_modules/pg/lib/connection.js:52:12)
2022-01-25T22:46:43.833830+00:00 app[web.1]: at Socket.emit (node:events:390:28)
2022-01-25T22:46:43.833830+00:00 app[web.1]: at emitErrorNT (node:internal/streams/destroy:157:8)
2022-01-25T22:46:43.833831+00:00 app[web.1]: at emitErrorCloseNT (node:internal/streams/destroy:122:3)
2022-01-25T22:46:43.833831+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:83:21) {
2022-01-25T22:46:43.833831+00:00 app[web.1]: parent: Error: connect ECONNREFUSED 127.0.0.1:5432
2022-01-25T22:46:43.833831+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
2022-01-25T22:46:43.833832+00:00 app[web.1]: errno: -111,
2022-01-25T22:46:43.833832+00:00 app[web.1]: code: 'ECONNREFUSED',
2022-01-25T22:46:43.833832+00:00 app[web.1]: syscall: 'connect',
2022-01-25T22:46:43.833833+00:00 app[web.1]: address: '127.0.0.1',
2022-01-25T22:46:43.833833+00:00 app[web.1]: port: 5432
2022-01-25T22:46:43.833833+00:00 app[web.1]: },
2022-01-25T22:46:43.833834+00:00 app[web.1]: original: Error: connect ECONNREFUSED 127.0.0.1:5432
2022-01-25T22:46:43.833834+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
2022-01-25T22:46:43.833834+00:00 app[web.1]: errno: -111,
2022-01-25T22:46:43.833834+00:00 app[web.1]: code: 'ECONNREFUSED',
2022-01-25T22:46:43.833835+00:00 app[web.1]: syscall: 'connect',
2022-01-25T22:46:43.833835+00:00 app[web.1]: address: '127.0.0.1',
2022-01-25T22:46:43.833835+00:00 app[web.1]: port: 5432
2022-01-25T22:46:43.833835+00:00 app[web.1]: }
2022-01-25T22:46:43.833835+00:00 app[web.1]: }
2022-01-25T22:46:43.841412+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/novousuario" host=penedocrud.herokuapp.com request_id=0b79d914-ec57-42c9-ab36-d274157b9913 fwd="186.194.175.39" dyno=web.1 connect=0ms service=393ms status=503 bytes=0 protocol=https
2022-01-25T22:46:44.010251+00:00 heroku[web.1]: Process exited with status 1
2022-01-25T22:46:44.064573+00:00 heroku[web.1]: State changed from up to crashed
2022-01-25T22:46:44.068523+00:00 heroku[web.1]: State changed from crashed to starting
2022-01-25T22:46:47.824479+00:00 heroku[web.1]: Starting process with command `npm start`
2022-01-25T22:46:48.950210+00:00 app[web.1]:
2022-01-25T22:46:48.950226+00:00 app[web.1]: > crud-tsnode#1.0.0 start
2022-01-25T22:46:48.950227+00:00 app[web.1]: > node dist/server.js
2022-01-25T22:46:48.950227+00:00 app[web.1]:
2022-01-25T22:46:49.481570+00:00 heroku[web.1]: State changed from starting to up
Here is my server.ts file:
import express, { Request, Response } from 'express';
import path from 'path';
import mustache from 'mustache-express';
import dotenv from 'dotenv';
import mainRoutes from './routes/index';
dotenv.config();
const server = express();
server.set('view engine', 'mustache');
server.set('views', path.join(__dirname, 'views'));
server.engine('mustache', mustache());
server.use(express.static(path.join(__dirname, '../public')));
server.use(express.urlencoded({extended: true}));
server.use(mainRoutes);
server.use((req: Request, res: Response)=>{
res.status(404).render('pages/404')
});
server.listen(process.env.PORT);
my routes:
import { Router } from "express";
import * as HomeController from '../controllers/homeController'
import * as UserController from '../controllers/userController'
import * as SearchController from '../controllers/searchController'
const router = Router()
router.get('/', HomeController.home)
router.get('/cadastro', HomeController.register)
router.get('/usuarios', UserController.users)
router.post('/novousuario', UserController.newUser)
router.get('/usuario/:id/editar', UserController.editUser)
router.get('/usuario/:id/excluir', UserController.deleteUser)
router.post('/novousuarioeditado/:id', UserController.newEditUser)
router.get('/search', SearchController.search)
export default router
looking through the browser it shows the error 503, there seems to be something wrong with the routes, when registering in the CRUD app, it should request the POST route and immediately redirect it to the users, but it simply gives an error in the application
remembering that everything is working locally, with no apparent errors
and , here is my package.json file:
{
"name": "crud-tsnode",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "16.x"
},
"scripts": {
"start": "node dist/server.js",
"tsc": "tsc",
"postinstall": "npm run tsc && copyfiles -u 1 src/**/*.mustache dist/",
"test": "echo \"Error: no test specified\" && exit 1",
"start-dev": "nodemon -e ts,json,mustache src/server.ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/FabioPenedo/Crud-tsnode.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/FabioPenedo/Crud-tsnode/issues"
},
"homepage": "https://github.com/FabioPenedo/Crud-tsnode#readme",
"dependencies": {
"dotenv": "^14.2.0",
"express": "^4.17.2",
"mustache-express": "^1.3.2",
"pg": "^8.7.1",
"pg-hstore": "^2.3.4",
"sequelize": "^6.13.0",
"typescript": "^4.5.5"
},
"devDependencies": {
"#types/express": "^4.17.13",
"#types/mustache-express": "^1.2.1",
"#types/node": "^17.0.10",
"#types/sequelize": "^4.28.11",
"copyfiles": "^2.4.1"
}
}
Port 5432 hints that your program is trying to connect to postgreSQL on localhost. That's probably the way it works in development on your own machine.
But, on Heroku your postgreSQL server is not on the same machine as your web dyno, so connecting to localhost:5432 does not work. The econnrefused error comes from the operating system, and it says that nothing is running on the port you tried to connect to.
Heroku, when you provision a postgreSQL database instance, gives you an environment variable called DATABASE_URL that's available to your app. You should use that to connect to your database.
I've created a single page app using the PERN stack and have successfully deployed it to Heroku. Now I am trying to switch to https on the backend, and have creaed a selfsigned.crt file and a selfsigned.key file, but I can't figure out this current error.
Here's my db.js
let connectionString = {
connectionString:
process.env.DATABASE_URL,
ssl: true,
};
const pool = new Pool(connectionString);
module.exports = pool;
Here's my server.js
const express = require("express");
const app = express();
const fs = require("fs");
const https = require("https");
const httpsPort = process.env.PORT || 8443;
const privateKey = fs.readFileSync("./sslCertification/selfsigned.key", "utf8");
const certificate = fs.readFileSync("./sslCertification/selfsigned.crt", "utf8");
const credentials = { key: privateKey, cert: certificate };
const priorityStatus = require("./routes/priorityStatus");
const accounts = require("./routes/accounts");
const projects = require("./routes/projects");
const bugs = require("./routes/bugs");
const comments = require("./routes/comments");
app.use(express.json());
app.all('*', function(req, res, next) {
if (req.headers['x-forwarded-proto'] != 'https')
res.redirect('https://' + req.headers.host + req.url)
else
next()
});
// Needed since single page application
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
}
app.get('*', (request, response) => {
response.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
app.use("/api/priority-status", priorityStatus);
app.use("/api/account", accounts);
app.use("/api/project", projects);
app.use("/api/bug", bugs);
app.use("/api/comment", comments);
const httpsServer = https.createServer(credentials, app);
httpsServer.listen(httpsPort);
// Was using this before switching to https
/* app.listen(process.env.PORT || 5000, () => {
console.log("Server has started on port 5000");
}); */
Here's what I get in my Heroku log --tail.
2020-12-16T23:45:25.843470+00:00 app[web.1]: [1] > server#1.0.0 client /app
2020-12-16T23:45:25.843471+00:00 app[web.1]: [1] > npm start --prefix ./client
2020-12-16T23:45:25.843472+00:00 app[web.1]: [1]
2020-12-16T23:45:26.287947+00:00 app[web.1]: [0]
2020-12-16T23:45:26.287959+00:00 app[web.1]: [0] > server#1.0.0 server /app
2020-12-16T23:45:26.287960+00:00 app[web.1]: [0] > npm start server.js
2020-12-16T23:45:26.287960+00:00 app[web.1]: [0]
2020-12-16T23:45:27.261503+00:00 app[web.1]: [1]
2020-12-16T23:45:27.261511+00:00 app[web.1]: [1] > client#0.1.0 start /app/client
2020-12-16T23:45:27.261512+00:00 app[web.1]: [1] > react-scripts start
2020-12-16T23:45:27.261512+00:00 app[web.1]: [1]
2020-12-16T23:45:27.287963+00:00 app[web.1]: [0]
2020-12-16T23:45:27.287965+00:00 app[web.1]: [0] > server#1.0.0 start /app
2020-12-16T23:45:27.287966+00:00 app[web.1]: [0] > node server.js "server.js"
2020-12-16T23:45:27.287966+00:00 app[web.1]: [0]
2020-12-16T23:45:29.329961+00:00 app[web.1]: [0] Server has started on port 5000
2020-12-16T23:45:29.377253+00:00 heroku[web.1]: State changed from starting to up
2020-12-16T23:45:31.082924+00:00 heroku[router]: at=info method=GET path="/" host=my-bug-tracker.herokuapp.com request_id=d77f6dfd-b5e2-4f8c-b5ec-6c8ca90063dd fwd="107.181.184.23" dyno=web.1 connect=1ms service=62ms status=200 bytes=2573 protocol=https
2020-12-16T23:45:31.327977+00:00 heroku[router]: at=info method=GET path="/static/js/main.627d6695.chunk.js" host=my-bug-tracker.herokuapp.com request_id=3e09e810-ba9b-4ffc-80ec-1452b4dc3fde fwd="107.181.184.23" dyno=web.1 connect=0ms service=8ms status=200 bytes=118886 protocol=https
2020-12-16T23:45:31.580398+00:00 heroku[router]: at=info method=GET path="/static/css/2.e6f51e71.chunk.css" host=my-bug-tracker.herokuapp.com request_id=fd127936-041d-4621-8417-4ab61d3be700 fwd="107.181.184.23" dyno=web.1 connect=1ms service=5ms status=200 bytes=30948 protocol=https
2020-12-16T23:45:31.766225+00:00 heroku[router]: at=info method=GET path="/static/css/main.baebc1a0.chunk.css" host=my-bug-tracker.herokuapp.com request_id=0cbed062-cc5a-4b0b-a5b5-9e0c6c126411 fwd="107.181.184.23" dyno=web.1 connect=0ms service=33ms status=200 bytes=51828 protocol=https
2020-12-16T23:45:31.800991+00:00 heroku[router]: at=info method=GET path="/static/js/2.86007984.chunk.js" host=my-bug-tracker.herokuapp.com request_id=4cb8b8f0-7a9f-4d19-b5e7-886956ff367b fwd="107.181.184.23" dyno=web.1 connect=0ms service=17ms status=200 bytes=256970 protocol=https
2020-12-16T23:45:32.395277+00:00 heroku[router]: at=info method=GET path="/static/media/BlueBackground_1920.f1fd53eb.jpg" host=my-bug-tracker.herokuapp.com request_id=fec9221a-2535-4a31-aa23-faae29fd9278 fwd="107.181.184.23" dyno=web.1 connect=0ms service=79ms status=200 bytes=193680 protocol=https
2020-12-16T23:45:32.435799+00:00 heroku[router]: at=info method=GET path="/bug-icon-white-background-thick.ico" host=my-bug-tracker.herokuapp.com request_id=2c3fcb80-9d59-4e2d-82cb-e40e069572fc fwd="107.181.184.23" dyno=web.1 connect=0ms service=11ms status=200 bytes=14451 protocol=https
2020-12-16T23:45:34.651092+00:00 app[web.1]: [1] Something is already running on port 32518.
2020-12-16T23:45:34.713739+00:00 app[web.1]: [1] npm run client exited with code 0
2020-12-16T23:45:38.231748+00:00 heroku[router]: at=info method=POST path="/api/account/login" host=my-bug-tracker.herokuapp.com request_id=a98b5798-90c0-43d5-951e-9eedb3caf308 fwd="107.181.184.23" dyno=web.1 connect=0ms service=365ms status=200 bytes=18030 protocol=https
2020-12-16T23:45:38.468324+00:00 heroku[router]: at=info method=GET path="/static/media/sort-arrows-both-empty.4823f7dd.svg" host=my-bug-tracker.herokuapp.com request_id=5ac2ebe3-eade-4929-ac13-a9c130ee49ba fwd="107.181.184.23" dyno=web.1 connect=0ms service=9ms status=200 bytes=2668 protocol=https
2020-12-16T23:45:38.469210+00:00 heroku[router]: at=info method=GET path="/static/media/sort-arrows-top-filled.d4ef80d2.svg" host=my-bug-tracker.herokuapp.com request_id=86e2dc2d-3cbd-49f3-9bff-d0318bfd88e6 fwd="107.181.184.23" dyno=web.1 connect=0ms service=10ms status=200 bytes=2700 protocol=https
2020-12-16T23:45:38.508359+00:00 heroku[router]: at=info method=GET path="/static/media/fontawesome-webfont.af7ae505.woff2" host=my-bug-tracker.herokuapp.com request_id=1c3618aa-6c2d-4849-9742-40b7cf76c25e fwd="107.181.184.23" dyno=web.1 connect=1ms service=10ms status=200 bytes=77438 protocol=https
2020-12-16T23:46:24.944613+00:00 heroku[router]: at=info method=GET path="/" host=my-bug-tracker.herokuapp.com request_id=0825b13a-7917-43d4-bcd9-c0c96df2dc06 fwd="107.181.184.23" dyno=web.1 connect=0ms service=3ms status=304 bytes=237 protocol=https
2020-12-16T23:46:25.177238+00:00 heroku[router]: at=info method=GET path="/static/css/2.e6f51e71.chunk.css" host=my-bug-tracker.herokuapp.com request_id=24c6a746-e906-49db-83ce-ccbe39a274ab fwd="107.181.184.23" dyno=web.1 connect=0ms service=4ms status=200 bytes=30948 protocol=https
2020-12-16T23:46:25.179901+00:00 heroku[router]: at=info method=GET path="/static/css/main.baebc1a0.chunk.css" host=my-bug-tracker.herokuapp.com request_id=d88baeaf-45ac-44fa-8e36-8b4a513c0e9f fwd="107.181.184.23" dyno=web.1 connect=1ms service=7ms status=200 bytes=51828 protocol=https
2020-12-16T23:46:25.184930+00:00 heroku[router]: at=info method=GET path="/static/js/2.86007984.chunk.js" host=my-bug-tracker.herokuapp.com request_id=23923f21-2b35-4eae-9ec4-a5bb511f7fc9 fwd="107.181.184.23" dyno=web.1 connect=0ms service=2ms status=304 bytes=239 protocol=https
2020-12-16T23:46:25.674846+00:00 heroku[router]: at=info method=GET path="/static/js/main.627d6695.chunk.js" host=my-bug-tracker.herokuapp.com request_id=92de810a-64b1-4723-ade4-f3af20f16914 fwd="107.181.184.23" dyno=web.1 connect=0ms service=2ms status=304 bytes=239 protocol=https
2020-12-16T23:46:25.895205+00:00 heroku[router]: at=info method=GET path="/static/media/BlueBackground_1920.f1fd53eb.jpg" host=my-bug-tracker.herokuapp.com request_id=8120bdf0-664b-42a5-9466-47ff254605e0 fwd="107.181.184.23" dyno=web.1 connect=0ms service=14ms status=200 bytes=193680 protocol=https
2020-12-16T23:46:26.005483+00:00 heroku[router]: at=info method=GET path="/bug-icon-white-background-thick.ico" host=my-bug-tracker.herokuapp.com request_id=6d37a9df-6bad-44c6-bf4c-4871036094b0 fwd="107.181.184.23" dyno=web.1 connect=1ms service=5ms status=200 bytes=14451 protocol=https
2020-12-17T00:17:57.035580+00:00 heroku[web.1]: Idling
2020-12-17T00:17:57.038063+00:00 heroku[web.1]: State changed from up to down
2020-12-17T00:17:58.600226+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-12-17T00:17:58.725162+00:00 heroku[web.1]: Process exited with status 143
2020-12-19T00:16:45.000000+00:00 app[api]: Build started by user myemail#outlook.com
2020-12-19T00:18:36.760218+00:00 app[api]: Release v32 created by user myemail#outlook.com
2020-12-19T00:18:36.760218+00:00 app[api]: Deploy a56a8d74 by user myemail#outlook.com
2020-12-19T00:18:37.085799+00:00 heroku[web.1]: State changed from down to starting
2020-12-19T00:18:38.000000+00:00 app[api]: Build succeeded
2020-12-19T00:18:46.854143+00:00 heroku[web.1]: Starting process with command `npm run dev`
2020-12-19T00:18:49.111701+00:00 app[web.1]:
2020-12-19T00:18:49.111720+00:00 app[web.1]: > server#1.0.0 dev /app
2020-12-19T00:18:49.111721+00:00 app[web.1]: > concurrently "npm run server" "npm run client"
2020-12-19T00:18:49.111721+00:00 app[web.1]:
2020-12-19T00:18:50.371711+00:00 app[web.1]: [0]
2020-12-19T00:18:50.371740+00:00 app[web.1]: [0] > server#1.0.0 server /app
2020-12-19T00:18:50.371741+00:00 app[web.1]: [0] > npm start server.js
2020-12-19T00:18:50.371741+00:00 app[web.1]: [0]
2020-12-19T00:18:50.685530+00:00 app[web.1]: [1]
2020-12-19T00:18:50.685542+00:00 app[web.1]: [1] > server#1.0.0 client /app
2020-12-19T00:18:50.685542+00:00 app[web.1]: [1] > npm start --prefix ./client
2020-12-19T00:18:50.685543+00:00 app[web.1]: [1]
2020-12-19T00:18:50.962753+00:00 app[web.1]: [0]
2020-12-19T00:18:50.962763+00:00 app[web.1]: [0] > server#1.0.0 start /app
2020-12-19T00:18:50.962764+00:00 app[web.1]: [0] > node server.js "server.js"
2020-12-19T00:18:50.962764+00:00 app[web.1]: [0]
2020-12-19T00:18:51.591232+00:00 heroku[web.1]: State changed from starting to up
2020-12-19T00:18:52.237451+00:00 app[web.1]: [1]
2020-12-19T00:18:52.237462+00:00 app[web.1]: [1] > client#0.1.0 start /app/client
2020-12-19T00:18:52.237463+00:00 app[web.1]: [1] > react-scripts start
2020-12-19T00:18:52.237464+00:00 app[web.1]: [1]
2020-12-19T00:18:54.475128+00:00 app[web.1]: [1] Something is already running on port 36160.
2020-12-19T00:18:54.500055+00:00 app[web.1]: [1] npm run client exited with code 0
2020-12-19T00:21:30.162248+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=my-bug-tracker.herokuapp.com request_id=d2dde696-e905-4999-b060-8f55e67638f8 fwd="73.133.94.85" dyno=web.1 connect=1ms service=8ms status=503 bytes=0 protocol=https
2020-12-19T00:23:04.490925+00:00 heroku[web.1]: Restarting
2020-12-19T00:23:04.507527+00:00 heroku[web.1]: State changed from up to starting
2020-12-19T00:23:05.356455+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-12-19T00:23:05.438828+00:00 heroku[web.1]: Process exited with status 143
2020-12-19T00:23:17.170024+00:00 heroku[web.1]: Starting process with command `npm run dev`
2020-12-19T00:23:20.333801+00:00 app[web.1]:
2020-12-19T00:23:20.333826+00:00 app[web.1]: > server#1.0.0 dev /app
2020-12-19T00:23:20.333827+00:00 app[web.1]: > concurrently "npm run server" "npm run client"
2020-12-19T00:23:20.333827+00:00 app[web.1]:
2020-12-19T00:23:21.436851+00:00 app[web.1]: [0]
2020-12-19T00:23:21.436873+00:00 app[web.1]: [0] > server#1.0.0 server /app
2020-12-19T00:23:21.436873+00:00 app[web.1]: [0] > npm start server.js
2020-12-19T00:23:21.436874+00:00 app[web.1]: [0]
2020-12-19T00:23:21.498752+00:00 app[web.1]: [1]
2020-12-19T00:23:21.498754+00:00 app[web.1]: [1] > server#1.0.0 client /app
2020-12-19T00:23:21.498754+00:00 app[web.1]: [1] > npm start --prefix ./client
2020-12-19T00:23:21.498755+00:00 app[web.1]: [1]
2020-12-19T00:23:22.064333+00:00 app[web.1]: [1]
2020-12-19T00:23:22.064355+00:00 app[web.1]: [1] > client#0.1.0 start /app/client
2020-12-19T00:23:22.064356+00:00 app[web.1]: [1] > react-scripts start
2020-12-19T00:23:22.064356+00:00 app[web.1]: [1]
2020-12-19T00:23:22.116724+00:00 app[web.1]: [0]
2020-12-19T00:23:22.116727+00:00 app[web.1]: [0] > server#1.0.0 start /app
2020-12-19T00:23:22.116729+00:00 app[web.1]: [0] > node server.js "server.js"
2020-12-19T00:23:22.116729+00:00 app[web.1]: [0]
2020-12-19T00:23:23.302719+00:00 heroku[web.1]: State changed from starting to up
2020-12-19T00:23:24.037351+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=my-bug-tracker.herokuapp.com request_id=6c715c5a-4f70-4e16-8a4c-307adb441f0a fwd="73.133.94.85" dyno=web.1 connect=1ms service=5ms status=503 bytes=0 protocol=https
2020-12-19T00:23:24.579638+00:00 app[web.1]: [1] Something is already running on port 9268.
2020-12-19T00:23:24.631826+00:00 app[web.1]: [1] npm run client exited with code 0
I have made a project through a course with Brad Traversy called contact keeper. It works fine locally on my machine and I get contact with the database.
Once I push it to Heroku I cant log in or register anymore. I get a 503 error (H10 & H13 errors from heroku) saying service unavailable when trying to hit those endpoints.
I have tried looking on similar threads but it does not work for me. I have added a procfile and checked through my package.json and it looks alright (from what I see).
The full repository can be found here: https://github.com/Dannus90/Contact_Keeper_MERN
const express = require('express');
const connectDB = require('./config/db');
const path = require('path');
const app = express();
// Connect Database
connectDB();
// Init Middleware
app.use(express.json({ extended: false }));
// Define Routes
app.use('/api/users', require('./routes/users'));
app.use('/api/auth', require('./routes/auth'));
app.use('/api/contacts', require('./routes/contacts'));
// Serve static assets in production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req, res) =>
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
);
}
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
In the picture below you can see where it fails. It is in the AuthState file when it tries to hit the endpoints.
The complete error log from heroku can be seen below:
2020-05-17T09:23:20.616623+00:00 heroku[web.1]: State changed from starting to up
2020-05-17T09:23:50.230066+00:00 app[web.1]: connection <monitor> to 52.31.65.44:27017 closed
2020-05-17T09:23:50.240114+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-17T09:23:50.240313+00:00 app[web.1]: npm ERR! errno 1
2020-05-17T09:23:50.241253+00:00 app[web.1]: npm ERR! contact-keeper#1.0.0 start: `node server.js`
2020-05-17T09:23:50.241374+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-17T09:23:50.241498+00:00 app[web.1]: npm ERR!
2020-05-17T09:23:50.241622+00:00 app[web.1]: npm ERR! Failed at the contact-keeper#1.0.0 start script.
2020-05-17T09:23:50.241760+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-17T09:23:50.249534+00:00 app[web.1]:
2020-05-17T09:23:50.249723+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-17T09:23:50.249843+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-05-17T09_23_50_242Z-debug.log
2020-05-17T09:23:50.311445+00:00 heroku[web.1]: State changed from up to crashed
2020-05-17T09:26:49.000000+00:00 app[api]: Build started by user persson.daniel.1990#gmail.com
2020-05-17T09:28:20.734327+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-17T09:28:20.461350+00:00 app[api]: Release v48 created by user persson.daniel.1990#gmail.com
2020-05-17T09:28:20.461350+00:00 app[api]: Deploy 502ce232 by user persson.daniel.1990#gmail.com
2020-05-17T09:28:21.000000+00:00 app[api]: Build succeeded
2020-05-17T09:28:30.543747+00:00 app[web.1]:
2020-05-17T09:28:30.543761+00:00 app[web.1]: > contact-keeper#1.0.0 start /app
2020-05-17T09:28:30.543761+00:00 app[web.1]: > node server.js
2020-05-17T09:28:30.543762+00:00 app[web.1]:
2020-05-17T09:28:31.157953+00:00 app[web.1]: Server started on port 13966
2020-05-17T09:28:32.044290+00:00 heroku[web.1]: State changed from starting to up
2020-05-17T09:28:33.217189+00:00 heroku[router]: at=info method=GET path="/" host=afternoon-earth-34040.herokuapp.com request_id=ed1492f5-d053-4ecf-8a88-8561992f3403 fwd="78.82.2.105" dyno=web.1 connect=0ms service=11ms status=200 bytes=2626 protocol=https
2020-05-17T09:28:33.348570+00:00 heroku[router]: at=info method=GET path="/static/css/main.abec718a.chunk.css" host=afternoon-earth-34040.herokuapp.com request_id=410da44d-797f-4a41-bafe-f130118e8c6d fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=200 bytes=4578 protocol=https
2020-05-17T09:28:33.346039+00:00 heroku[router]: at=info method=GET path="/static/js/main.6e77bd50.chunk.js" host=afternoon-earth-34040.herokuapp.com request_id=018e556e-91d6-4944-bd6e-0c5b74ece68a fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=200 bytes=28978 protocol=https
2020-05-17T09:28:33.474881+00:00 heroku[router]: at=info method=GET path="/static/js/2.9c49eab7.chunk.js" host=afternoon-earth-34040.herokuapp.com request_id=5379490e-fd9b-47c1-b001-15e036784e2d fwd="78.82.2.105" dyno=web.1 connect=0ms service=10ms status=200 bytes=192222 protocol=https
2020-05-17T09:28:33.992494+00:00 heroku[router]: at=info method=GET path="/api/contacts" host=afternoon-earth-34040.herokuapp.com request_id=3684bbba-83b1-4d90-b9f8-d4ba7dedbc60 fwd="78.82.2.105" dyno=web.1 connect=0ms service=2ms status=401 bytes=257 protocol=https
2020-05-17T09:28:33.990977+00:00 heroku[router]: at=info method=GET path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=705c0086-3927-4e6f-b2dd-45ac9165e303 fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=401 bytes=257 protocol=https
2020-05-17T09:28:34.365542+00:00 heroku[router]: at=info method=GET path="/manifest.json" host=afternoon-earth-34040.herokuapp.com request_id=1f38b786-2c3d-411e-8aee-6862c40e77d4 fwd="78.82.2.105" dyno=web.1 connect=1ms service=6ms status=200 bytes=787 protocol=https
2020-05-17T09:28:34.483877+00:00 heroku[router]: at=info method=GET path="/logo192.png" host=afternoon-earth-34040.herokuapp.com request_id=65807958-8954-4332-8cab-dc4320e2cac8 fwd="78.82.2.105" dyno=web.1 connect=0ms service=2ms status=200 bytes=5622 protocol=https
2020-05-17T09:28:42.084546+00:00 heroku[router]: at=info method=GET path="/static/js/2.9c49eab7.chunk.js.map" host=afternoon-earth-34040.herokuapp.com request_id=d186f408-b227-4ce3-8f6d-2858c2b6b5a0 fwd="78.82.2.105" dyno=web.1 connect=0ms service=18ms status=200 bytes=624338 protocol=https
2020-05-17T09:28:42.056584+00:00 heroku[router]: at=info method=GET path="/static/css/main.abec718a.chunk.css" host=afternoon-earth-34040.herokuapp.com request_id=4ebde32e-fca4-4968-89d2-e10af56e5ad3 fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=304 bytes=238 protocol=https
2020-05-17T09:28:42.176331+00:00 heroku[router]: at=info method=GET path="/static/js/main.6e77bd50.chunk.js.map" host=afternoon-earth-34040.herokuapp.com request_id=22d537d1-9c6e-445b-985a-78f2319dd192 fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=200 bytes=61221 protocol=https
2020-05-17T09:28:42.289347+00:00 heroku[router]: at=info method=GET path="/static/css/main.abec718a.chunk.css.map" host=afternoon-earth-34040.herokuapp.com request_id=7418f08d-9c43-47e0-b2d3-2f2d23652356 fwd="78.82.2.105" dyno=web.1 connect=0ms service=2ms status=200 bytes=15892 protocol=https
2020-05-17T09:29:01.254923+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=82f5a82c-e065-4e9e-a284-a82ba86287d2 fwd="78.82.2.105" dyno=web.1 connect=0ms service=15877ms status=503 bytes=0 protocol=https
2020-05-17T09:29:01.362981+00:00 heroku[web.1]: State changed from up to crashed
2020-05-17T09:29:01.235846+00:00 app[web.1]: connection <monitor> to 54.72.107.147:27017 closed
2020-05-17T09:29:01.262738+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-17T09:29:01.263049+00:00 app[web.1]: npm ERR! errno 1
2020-05-17T09:29:01.263998+00:00 app[web.1]: npm ERR! contact-keeper#1.0.0 start: `node server.js`
2020-05-17T09:29:01.264159+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-17T09:29:01.264337+00:00 app[web.1]: npm ERR!
2020-05-17T09:29:01.264484+00:00 app[web.1]: npm ERR! Failed at the contact-keeper#1.0.0 start script.
2020-05-17T09:29:01.264618+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-17T09:29:01.270789+00:00 app[web.1]:
2020-05-17T09:29:01.270997+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-17T09:29:01.271145+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-05-17T09_29_01_265Z-debug.log
2020-05-17T09:29:01.256625+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=0e0e84a4-257b-43bd-a31d-b97ebaed5a10 fwd="78.82.2.105" dyno=web.1 connect=0ms service=16031ms status=503 bytes=0 protocol=https
2020-05-17T09:29:01.256627+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=acbb4fdf-bf07-4668-886e-a253a3e0aee3 fwd="78.82.2.105" dyno=web.1 connect=0ms service=15442ms status=503 bytes=0 protocol=https
2020-05-17T09:29:01.257557+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=1a45a04e-0c1e-47ea-b796-7299db72f732 fwd="78.82.2.105" dyno=web.1 connect=0ms service=21480ms status=503 bytes=0 protocol=https
2020-05-17T09:29:01.257996+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=2531aa80-5bf8-42e8-b620-ff9f2969ba1f fwd="78.82.2.105" dyno=web.1 connect=0ms service=15579ms status=503 bytes=0 protocol=https
2020-05-17T09:29:04.000000+00:00 app[api]: Build started by user persson.daniel.1990#gmail.com
2020-05-17T09:30:32.857023+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-17T09:30:32.560586+00:00 app[api]: Release v49 created by user persson.daniel.1990#gmail.com
2020-05-17T09:30:32.560586+00:00 app[api]: Deploy aba0d37e by user persson.daniel.1990#gmail.com
2020-05-17T09:30:34.000000+00:00 app[api]: Build succeeded
2020-05-17T09:30:44.786119+00:00 app[web.1]:
2020-05-17T09:30:44.786136+00:00 app[web.1]: > contact-keeper#1.0.0 start /app
2020-05-17T09:30:44.786137+00:00 app[web.1]: > node server.js
2020-05-17T09:30:44.786137+00:00 app[web.1]:
2020-05-17T09:30:45.574040+00:00 app[web.1]: Server started on port 52681
2020-05-17T09:30:46.081535+00:00 heroku[web.1]: State changed from starting to up
2020-05-17T09:31:15.677435+00:00 app[web.1]: connection <monitor> to 52.31.65.44:27017 closed
2020-05-17T09:31:15.698356+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-17T09:31:15.698666+00:00 app[web.1]: npm ERR! errno 1
2020-05-17T09:31:15.699733+00:00 app[web.1]: npm ERR! contact-keeper#1.0.0 start: `node server.js`
2020-05-17T09:31:15.699922+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-17T09:31:15.700135+00:00 app[web.1]: npm ERR!
2020-05-17T09:31:15.700312+00:00 app[web.1]: npm ERR! Failed at the contact-keeper#1.0.0 start script.
2020-05-17T09:31:15.700467+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-17T09:31:15.723946+00:00 app[web.1]:
2020-05-17T09:31:15.724237+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-17T09:31:15.724392+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-05-17T09_31_15_704Z-debug.log
2020-05-17T09:31:15.828237+00:00 heroku[web.1]: State changed from up to crashed
2020-05-17T09:35:10.524783+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-17T09:35:21.345206+00:00 app[web.1]:
2020-05-17T09:35:21.345238+00:00 app[web.1]: > contact-keeper#1.0.0 start /app
2020-05-17T09:35:21.345238+00:00 app[web.1]: > node server.js
2020-05-17T09:35:21.345239+00:00 app[web.1]:
2020-05-17T09:35:22.181653+00:00 app[web.1]: Server started on port 57715
2020-05-17T09:35:22.526258+00:00 heroku[web.1]: State changed from starting to up
2020-05-17T09:35:52.241989+00:00 app[web.1]: connection <monitor> to 54.72.107.147:27017 closed
2020-05-17T09:35:52.255501+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-17T09:35:52.256048+00:00 app[web.1]: npm ERR! errno 1
2020-05-17T09:35:52.257707+00:00 app[web.1]: npm ERR! contact-keeper#1.0.0 start: `node server.js`
2020-05-17T09:35:52.258009+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-17T09:35:52.258313+00:00 app[web.1]: npm ERR!
2020-05-17T09:35:52.258505+00:00 app[web.1]: npm ERR! Failed at the contact-keeper#1.0.0 start script.
2020-05-17T09:35:52.258686+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-17T09:35:52.266384+00:00 app[web.1]:
2020-05-17T09:35:52.266689+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-17T09:35:52.266864+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-05-17T09_35_52_259Z-debug.log
2020-05-17T09:35:52.425747+00:00 heroku[web.1]: State changed from up to crashed
2020-05-17T09:37:40.075229+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=afternoon-earth-34040.herokuapp.com request_id=b86ff65a-3c2f-4609-85ba-a75500f93e3a fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
2020-05-17T09:37:40.189972+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=afternoon-earth-34040.herokuapp.com request_id=d5b50b56-a5df-4d19-9c0f-6298c0dea421 fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
2020-05-17T09:37:42.254860+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/login" host=afternoon-earth-34040.herokuapp.com request_id=20cdf3b9-5883-4dcd-898a-03eb6ee20dc5 fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
2020-05-17T09:37:43.970046+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/login" host=afternoon-earth-34040.herokuapp.com request_id=dc0e7da8-46fa-4da1-bdb6-4814157e43a5 fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
2020-05-17T09:37:44.242232+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=afternoon-earth-34040.herokuapp.com request_id=53adb339-25bb-4bca-9b89-638035820973 fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
This is the code from my db file:
const mongoose = require("mongoose");
const config = require("config");
const db = config.get("mongoURI");
const connectDB = async () => {
try {
await mongoose.connect(db, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
});
console.log("MongoDB Connected");
} catch (err) {
console.error(err.message);
process.exit(1);
}
};
module.exports = connectDB;
This is the database (found in default and production.js):
{
"mongoURI": "mongodb+srv://Daniel123:Daniel123#contactkeeper-rjjr4.mongodb.net/test?retryWrites=true&w=majority",
"jwtSecret": "secret"
}
Solution for me for this problem (incase anyone else get the problem):
I whitelisted 0.0.0.0/0 on mongodb, set environmental variables on heroku and set them as an alternative for the db connect(same with jwtSecret in the config), since the config was ignored when pushing to heroku:
const mongoose = require("mongoose");
const config = require("config");
const db = config.get("mongoURI");
const connectDB = async () => {
try {
await mongoose.connect(db || process.env.mongoURI, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
});
console.log("MongoDB Connected");
} catch (err) {
console.error(err.message);
process.exit(1);
}
};
module.exports = connectDB;
I deployed a Node.js application on Heroku through CLI. The steps I followed are
Git add .
Git commit -am "message"
git heroku push master
heroku open
I didnt get any error and when I run heroku open, the app is running on my browser. The problem is that when I try to run it using different browsers or through mobile browser its not loading.
This is the url : https://smit21.herokuapp.com/
Heroku logs:
2018-09-22T10:45:10.910105+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T10:45:11.024839+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T10:45:11.730224+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=3da0a9c2-6a20-4f07-9832-03384d0030f0 fwd="130.217.199.41" dyno=web.1 connect=1ms service=15ms status=304 bytes=149 protocol=https
2018-09-22T10:45:22.179407+00:00 heroku[router]: at=info method=GET path="/style.css" host=smit21.herokuapp.com request_id=9e8e12f2-3a10-4737-ad59-5a80fc543e15 fwd="130.217.199.41" dyno=web.1 connect=0ms service=22ms status=200 bytes=1671 protocol=https
2018-09-22T10:45:22.467080+00:00 heroku[router]: at=info method=GET path="/service-worker.js" host=smit21.herokuapp.com request_id=23c73ab0-c7dc-4795-8071-96f227c25de7 fwd="130.217.199.41" dyno=web.1 connect=0ms service=6ms status=200 bytes=1671 protocol=https
2018-09-22T10:46:42.380939+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=3d720461-a453-4406-ab50-e619e4a1ca17 fwd="130.217.199.41" dyno=web.1 connect=1ms service=4ms status=304 bytes=149 protocol=https
2018-09-22T11:20:22.770459+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=12c5acba-bf57-4fff-b105-872666b2cedb fwd="130.217.252.116" dyno=web.1 connect=1ms service=3ms status=200 bytes=205 protocol=http
2018-09-22T11:20:23.078071+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=b4012891-eeb7-4475-93e0-42b95464b751 fwd="130.217.252.116" dyno=web.1 connect=1ms service=11ms status=200 bytes=1671 protocol=http
2018-09-22T11:21:23.714105+00:00 heroku[web.1]: Idling
2018-09-22T11:21:23.714612+00:00 heroku[web.1]: State changed from up to down
2018-09-22T11:21:24.902989+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T11:21:25.009609+00:00 heroku[web.1]: Process exited with status 143
2018-09-22T12:19:21.492774+00:00 heroku[web.1]: Unidling
2018-09-22T12:19:21.493013+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T12:19:31.538143+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-22T12:19:34.484663+00:00 app[web.1]:
2018-09-22T12:19:34.484689+00:00 app[web.1]: > connectify#1.0.0 start /app
2018-09-22T12:19:34.484691+00:00 app[web.1]: > node server.js
2018-09-22T12:19:34.484692+00:00 app[web.1]:
2018-09-22T12:19:36.922548+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T12:19:36.806116+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-22T12:19:36.808856+00:00 app[web.1]: server running on ${port}
2018-09-22T12:19:37.512586+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T12:19:37.644321+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=ee35c390-7a01-47cd-a735-fbc0a09dfa17 fwd="67.81.155.224" dyno=web.1 connect=1ms service=33ms status=200 bytes=205 protocol=https
2018-09-22T12:19:38.625988+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=59431a7d-0435-482e-be56-bc40ec0d7040 fwd="67.81.155.224" dyno=web.1 connect=1ms service=18ms status=200 bytes=1671 protocol=https
2018-09-22T12:37:21.169018+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=a7f0cd4d-564d-4b2c-b2f5-c6b447cf113d fwd="42.113.162.220" dyno=web.1 connect=0ms service=8ms status=200 bytes=205 protocol=https
2018-09-22T12:37:21.688111+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=e942379d-0505-4c52-8a79-06774538178a fwd="42.113.162.220" dyno=web.1 connect=0ms service=6ms status=200 bytes=1671 protocol=https
2018-09-22T13:12:41.189319+00:00 heroku[web.1]: Idling
2018-09-22T13:12:41.189770+00:00 heroku[web.1]: State changed from up to down
2018-09-22T13:12:42.083740+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T13:12:42.244254+00:00 heroku[web.1]: Process exited with status 143
2018-09-22T13:40:40.011490+00:00 heroku[web.1]: Unidling
2018-09-22T13:40:40.011737+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T13:40:49.782284+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-22T13:40:52.738181+00:00 app[web.1]:
2018-09-22T13:40:52.738215+00:00 app[web.1]: > connectify#1.0.0 start /app
2018-09-22T13:40:52.738216+00:00 app[web.1]: > node server.js
2018-09-22T13:40:52.738217+00:00 app[web.1]:
2018-09-22T13:40:56.345158+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-22T13:40:56.347202+00:00 app[web.1]: server running on ${port}
2018-09-22T13:40:56.727105+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T13:40:57.065561+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T13:40:58.175235+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=11684ba9-34ff-4e3c-b80d-bb4738826fba fwd="185.20.6.43" dyno=web.1 connect=1ms service=27ms status=200 bytes=205 protocol=https
2018-09-22T14:13:38.051816+00:00 heroku[web.1]: Idling
2018-09-22T14:13:38.052343+00:00 heroku[web.1]: State changed from up to down
2018-09-22T14:13:39.140424+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T14:13:39.513941+00:00 heroku[web.1]: Process exited with status 143
2018-09-22T17:49:30.699850+00:00 heroku[web.1]: Unidling
2018-09-22T17:49:30.700095+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T17:49:30.712308+00:00 heroku[web.1]: Unidling
2018-09-22T17:49:30.712582+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T17:49:40.987766+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-22T17:49:43.759282+00:00 app[web.1]:
2018-09-22T17:49:43.759314+00:00 app[web.1]: > connectify#1.0.0 start /app
2018-09-22T17:49:43.759315+00:00 app[web.1]: > node server.js
2018-09-22T17:49:43.759316+00:00 app[web.1]:
2018-09-22T17:49:46.124612+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-22T17:49:46.126979+00:00 app[web.1]: server running on ${port}
2018-09-22T17:49:46.522505+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T17:49:46.644735+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T17:49:48.917314+00:00 heroku[router]: at=info method=GET path="/robots.txt" host=smit21.herokuapp.com request_id=903a4039-97bc-4828-812b-f1acc2cdc513 fwd="37.170.118.162" dyno=web.1 connect=0ms service=68ms status=200 bytes=1671 protocol=https
2018-09-22T17:49:48.876338+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=9e23b162-b656-447f-a89e-ae5130b3b8bc fwd="37.170.118.162" dyno=web.1 connect=1ms service=31ms status=200 bytes=205 protocol=https
2018-09-22T17:49:51.070701+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=3aaa52db-476e-411f-b6aa-8158dff352cd fwd="37.170.118.162" dyno=web.1 connect=0ms service=8ms status=200 bytes=1671 protocol=https
2018-09-22T18:27:03.807779+00:00 heroku[web.1]: Idling
2018-09-22T18:27:03.808281+00:00 heroku[web.1]: State changed from up to down
2018-09-22T18:27:04.892238+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T18:27:05.038741+00:00 heroku[web.1]: Process exited with status 143
2018-09-22T22:01:22.982040+00:00 heroku[web.1]: Unidling
2018-09-22T22:01:22.982330+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T22:01:33.438308+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-22T22:01:36.517339+00:00 app[web.1]:
2018-09-22T22:01:36.517389+00:00 app[web.1]: > connectify#1.0.0 start /app
2018-09-22T22:01:36.517391+00:00 app[web.1]: > node server.js
2018-09-22T22:01:36.517392+00:00 app[web.1]:
2018-09-22T22:01:39.339911+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-22T22:01:39.348746+00:00 app[web.1]: server running on ${port}
2018-09-22T22:01:39.761169+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T22:01:39.933342+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T22:01:41.162080+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=d176ed5c-f629-4964-8e78-2bb73b521af3 fwd="185.20.6.141" dyno=web.1 connect=0ms service=26ms status=200 bytes=205 protocol=https
2018-09-22T22:36:02.306389+00:00 heroku[web.1]: Idling
2018-09-22T22:36:02.306919+00:00 heroku[web.1]: State changed from up to down
2018-09-22T22:36:03.163997+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T22:36:03.277923+00:00 heroku[web.1]: Process exited with status 143
2018-09-23T00:13:07.000615+00:00 heroku[web.1]: Unidling
2018-09-23T00:13:07.000863+00:00 heroku[web.1]: State changed from down to starting
2018-09-23T00:13:12.849997+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-23T00:13:14.641841+00:00 app[web.1]:
2018-09-23T00:13:14.641858+00:00 app[web.1]: > connectify#1.0.0 start /app
2018-09-23T00:13:14.641860+00:00 app[web.1]: > node server.js
2018-09-23T00:13:14.641861+00:00 app[web.1]:
2018-09-23T00:13:15.926398+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-23T00:13:15.927682+00:00 app[web.1]: server running on ${port}
2018-09-23T00:13:16.612593+00:00 heroku[web.1]: State changed from starting to up
2018-09-23T00:13:16.526867+00:00 app[web.1]: mongo is successfully Connected
2018-09-23T00:13:19.158301+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=1753b2d3-291f-4cc4-a02d-184ed39337e9 fwd="24.87.72.248" dyno=web.1 connect=0ms service=10ms status=200 bytes=205 protocol=https
2018-09-23T00:13:19.821530+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=a4270213-9ac1-4e68-827f-ea7e9ac365ba fwd="24.87.72.248" dyno=web.1 connect=0ms service=13ms status=200 bytes=1671 protocol=https
2018-09-23T00:49:06.417379+00:00 heroku[web.1]: Idling
2018-09-23T00:49:06.417954+00:00 heroku[web.1]: State changed from up to down
2018-09-23T00:49:07.535197+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-23T00:49:07.751341+00:00 heroku[web.1]: Process exited with status 143
Screenshot when trying to run heroku open
server.js
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');
const path = require('path');
const users = require('./routes/api/users');
const profile = require('./routes/api/profile');
const posts = require('./routes/api/posts');
const app = express();
// Body parser 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)
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log(err));
// Passport middleware
app.use(passport.initialize());
// Passport Config
require('./config/passport')(passport);
// Use Routes
app.use('/api/users', users);
app.use('/api/profile', profile);
app.use('/api/posts', posts);
// Server static assets if in production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server running on port ${port}`));
package.json
"heroku-postbuild":
"NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"
I created an React app (using CRA) with Nodejs backend. Now I tried hosting it. (I've hosted few apps with same stack but didn't faced any issues).
I'm starting both Nodejs and React app using concurrently module with npm run dev.
But this time I'm getting an error and I can't figure out why.
This is what I get when I go the link.
Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.
index.js
const express = require('express');
const routes = require('./routes');
const app = express();
const port = 5000 || process.env.PORT;
routes(app);
if(process.env.NODE_ENV === 'production'){
app.use(express.static('client/build'));
const path = require('path');
app.get("*", (req,res) => {
res.sendFile(path.resolve(__dirname,'client','build','index.html'));
})
}
app.listen(port, () => console.log(`Server is running on port ${port}`));
package.json
{
"name": "check-market",
"version": "1.0.0",
"description": "This is a react-nodejs based crypto market checking app",
"main": "index.js",
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"author": "abcd",
"license": "ISC",
"dependencies": {
"concurrently": "^3.5.1",
"cryptocoins-icons": "^2.7.0",
"express": "^4.16.2",
"node-fetch": "^2.0.0",
"nodemon": "^1.14.12"
}
}
heroku logs
2018-04-05T13:41:49.283535+00:00 app[web.1]: [1]2018-04-05T13:41:49.560174+00:00 app[web.1]: [0] Server is running on port 5000
2018-04-05T13:41:51.049613+00:00 app[web.1]: [1] Starting the development server...
2018-04-05T13:41:51.049625+00:00 app[web.1]: [1]
2018-04-05T13:41:51.202463+00:00 heroku[web.1]: State changed from starting to up
2018-04-05T13:42:00.969286+00:00 app[web.1]: [1] Compiled with warnings.
2018-04-05T13:42:00.969303+00:00 app[web.1]: [1]
2018-04-05T13:42:00.969584+00:00 app[web.1]: [1] ./src/components/currency_main.js
2018-04-05T13:42:00.969587+00:00 app[web.1]: [1] Line 49: Expected to return a value in arrow function array-callback-return
2018-04-05T13:42:00.969588+00:00 app[web.1]: [1]
2018-04-05T13:42:00.969590+00:00 app[web.1]: [1] Search for the keywords to learn more about each warning.
2018-04-05T13:42:00.969593+00:00 app[web.1]: [1] To ignore, add // eslint-disable-next-line to the line before.
2018-04-05T13:42:00.969594+00:00 app[web.1]: [1]2018-04-05T13:42:17.377067+00:00 heroku[router]: at=info method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=fa334992-ebb7-4a38-8c2d-e5c09849dcef fwd="112.134.75.196" dyno=web.1 connect=1ms service=13ms status=200 bytes=219 protocol=https
2018-04-05T13:42:18.397503+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=e716c9cb-e910-4f98-8346-4195c6d623ca fwd="112.134.75.196" dyno=web.1 connect=0ms service=7ms status=200 bytes=219 protocol=https
2018-04-05T13:44:47.000000+00:00 app[api]: Build started by user thidasaone#gmail.com
2018-04-05T13:44:47.000000+00:00 app[api]: Build succeeded
2018-04-05T13:46:08.491686+00:00 app[api]: Deploy 0ae9d4f3 by user thidasaone#gmail.com2018-04-05T13:46:08.491686+00:00 app[api]: Release v8 created by user thidasaone#gmail.com2018-04-05T13:46:10.417551+00:00 heroku[web.1]: Restarting
2018-04-05T13:46:10.418403+00:00 heroku[web.1]: State changed from up to starting2018-04-05T13:46:12.169322+00:00 heroku[web.1]: Stopping all processes with SIGTERM2018-04-05T13:46:12.258942+00:00 heroku[web.1]: Process exited with status 143
2018-04-05T13:46:17.859328+00:00 heroku[web.1]: Starting process with command `npm run dev`2018-04-05T13:46:20.219087+00:00 app[web.1]:2018-04-05T13:46:20.219128+00:00 app[web.1]: > check-market#1.0.0 dev /app
2018-04-05T13:46:20.219130+00:00 app[web.1]: > concurrently "npm run server" "npm run client"2018-04-05T13:46:20.219132+00:00 app[web.1]:2018-04-05T13:46:20.817238+00:00 app[web.1]: [0]
2018-04-05T13:46:20.817262+00:00 app[web.1]: [0] > check-market#1.0.0 server /app
2018-04-05T13:46:20.817265+00:00 app[web.1]: [0] > nodemon index.js
2018-04-05T13:46:20.817267+00:00 app[web.1]: [0]
2018-04-05T13:46:20.865621+00:00 app[web.1]: [1]
2018-04-05T13:46:20.865626+00:00 app[web.1]: [1] > check-market#1.0.0 client /app
2018-04-05T13:46:20.865635+00:00 app[web.1]: [1] > npm run start --prefix client
2018-04-05T13:46:20.865636+00:00 app[web.1]: [1]
2018-04-05T13:46:21.154092+00:00 app[web.1]: [0] [nodemon] 1.14.12
2018-04-05T13:46:21.155353+00:00 app[web.1]: [0] [nodemon] to restart at any time, enter `rs`
2018-04-05T13:46:21.155695+00:00 app[web.1]: [0] [nodemon] watching: *.*
2018-04-05T13:46:21.156422+00:00 app[web.1]: [0] [nodemon] starting `node index.js`
2018-04-05T13:46:21.225033+00:00 app[web.1]: [1]
2018-04-05T13:46:21.225037+00:00 app[web.1]: [1] > client#0.1.0 start /app/client
2018-04-05T13:46:21.225039+00:00 app[web.1]: [1] > react-scripts start
2018-04-05T13:46:21.225041+00:00 app[web.1]: [1]
2018-04-05T13:46:21.390693+00:00 app[web.1]: [0] Server is running on port 5000
2018-04-05T13:46:22.929315+00:00 app[web.1]: [1] [HPM] Proxy created: function (pathname) {
2018-04-05T13:46:22.929329+00:00 app[web.1]: [1] return mayProxy(pathname) && pathname.match(context);
2018-04-05T13:46:22.929331+00:00 app[web.1]: [1] } -> http://localhost:5000
2018-04-05T13:46:22.940428+00:00 app[web.1]: [1] Starting the development server...
2018-04-05T13:46:22.940431+00:00 app[web.1]: [1]
2018-04-05T13:46:23.520069+00:00 heroku[web.1]: State changed from starting to up
2018-04-05T13:46:31.231306+00:00 heroku[router]: at=info method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=ec7762d5-3d9d-4512-96bf-5e51fd57e531 fwd="112.134.75.196" dyno=web.1 connect=1ms service=35ms status=304 bytes=150 protocol=https
2018-04-05T13:46:32.041938+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=51901fca-b454-4e15-891f-54157d6ecffa fwd="112.134.75.196" dyno=web.1 connect=1ms service=74ms status=304 bytes=150 protocol=https
2018-04-05T13:46:34.656623+00:00 app[web.1]: [1]
2018-04-05T13:46:34.656609+00:00 app[web.1]: [1] Compiled with warnings.
2018-04-05T13:46:34.656627+00:00 app[web.1]: [1] Line 49: Expected to return a value in arrow function array-callback-return
2018-04-05T13:46:34.656629+00:00 app[web.1]: [1]
2018-04-05T13:46:34.656650+00:00 app[web.1]: [1] Search for the keywords to learn more about each warning.
2018-04-05T13:46:34.656625+00:00 app[web.1]: [1] ./src/components/currency_main.js
2018-04-05T13:46:34.656652+00:00 app[web.1]: [1] To ignore, add // eslint-disable-next-line to the line before.
2018-04-05T13:46:34.656654+00:00 app[web.1]: [1]
2018-04-05T13:47:01.000000+00:00 app[api]: Build started by user thidasaone#gmail.com
2018-04-05T13:48:18.696342+00:00 heroku[router]: at=info method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=9b941ec9-ac57-465f-8270-ff6b576e7a7e fwd="112.134.75.196" dyno=web.1 connect=1ms service=4ms status=304 bytes=150 protocol=https
2018-04-05T13:48:19.715353+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=9dce4cdb-3251-4371-a6dc-17f5157c4c91 fwd="112.134.75.196" dyno=web.1 connect=1ms service=4ms status=200 bytes=219 protocol=https
2018-04-05T13:48:23.281435+00:00 heroku[web.1]: Restarting
2018-04-05T13:48:23.283219+00:00 heroku[web.1]: State changed from up to starting
2018-04-05T13:48:24.367174+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-04-05T13:48:24.460758+00:00 heroku[web.1]: Process exited with status 143
2018-04-05T13:48:22.235400+00:00 app[api]: Deploy f9c11456 by user thidasaone#gmail.com
2018-04-05T13:48:22.235400+00:00 app[api]: Release v9 created by user thidasaone#gmail.com
2018-04-05T13:47:01.000000+00:00 app[api]: Build succeeded
2018-04-05T13:48:31.022921+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-05T13:48:32.988916+00:00 app[web.1]:
2018-04-05T13:48:32.988939+00:00 app[web.1]: > check-market#1.0.0 start /app
2018-04-05T13:48:32.988941+00:00 app[web.1]: > node index.js
2018-04-05T13:48:32.988943+00:00 app[web.1]:
2018-04-05T13:48:33.185499+00:00 app[web.1]: Server is running on port 5000
2018-04-05T13:49:31.116916+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2018-04-05T13:49:31.093326+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 secondsof launch
2018-04-05T13:49:31.093493+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-04-05T13:49:31.174105+00:00 heroku[web.1]: Process exited with status 22
2018-04-05T13:49:31.188588+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-05T13:49:31.190801+00:00 heroku[web.1]: State changed from crashed to starting
2018-04-05T13:49:41.680073+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-05T13:49:44.021163+00:00 app[web.1]:
2018-04-05T13:49:44.021180+00:00 app[web.1]: > check-market#1.0.0 start /app
2018-04-05T13:49:44.021181+00:00 app[web.1]: > node index.js
2018-04-05T13:49:44.021183+00:00 app[web.1]:
2018-04-05T13:49:44.261412+00:00 app[web.1]: Server is running on port 5000
2018-04-05T13:50:24.659139+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=19ee5172-d09e-4a14-bec5-7332c5b8b572 fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:50:42.173853+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 secondsof launch
2018-04-05T13:50:42.173971+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-04-05T13:50:42.278113+00:00 heroku[web.1]: Process exited with status 137
2018-04-05T13:50:42.292645+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-05T13:50:44.109644+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=457aceaf-7149-4cd8-aaf0-1e9746c2e7a9 fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:50:46.073884+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=6d2ed2ed-a2dc-4b77-80f1-099d442e16db fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:50:55.112767+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=51e6ee29-3f28-4dc1-bc69-b58604b6524b fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:51:02.307944+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=5e366ae1-6d66-4015-85ad-e407316d083f fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:51:24.537650+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=8483caf1-1e99-4735-a16e-8df0d09b3d20 fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:51:27.770178+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=28e8927c-21ac-44c5-84e5-093f55c95aeb fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
As I read in heroku logs, I know there's an issue (as it mentions). But I can't figure out what it is as what I've followed the same steps as before (same as I hosted other apps on Heroku)
Can anyone tell me what have I done wrong ?
P.S :
I've checked this and added Procfile and then I got an issue with React App saying Invalid Header File . So I removed it (as Heroku has made the process automatically sometime after the post)
And I checked with this as well but I don't think it'll be any help.
Try adding the config vars into your heroku app by going through
Your app => Settings => Reveal Config vars => Add PORT 5000 in it
I had the same exact issue, I have added the PORT 5000 as mentioned above, but it alone didn't resolve my issue.
Anyway by checking the build logs, I found the following error:
Error: Configuration property "mongoURI" is not defined
The production.json file was in .gitignore file, and by removing it from .gitignore and pushing it to Heroku the issue was resolved.