Open dallli92 opened 5 years ago
I am getting the same error too. The problem seems to be related to the URL starting with "mongodb+srv". Also, I am using Mongo DB Atlas for the database as we can no longer create a mongodb account..
Same error for me as well. Please help to resolve. Getting Application error after successful deployment.
hey, I just found a solution
update version your mongodb package on package.json "mongoose": "5.8.3", "passport-local-mongoose": "5.0.0", "mongodb-core": "3.2.7"
Also remember to add this ip config network access on your Mongo DB Atlas: "0.0.0.0/0". No special character (#,%...) on your account password for access database Deploy again and it will work perfectly.
@duchuy-13 thanks man! This solves it.
hello, i already updated mongodb version on package.json but it's still fail 2020-08-20T13:59:17.461350+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with: 2020-08-20T13:59:17.461506+00:00 app[web.1]: npm ERR! npm bugs slacky-slack 2020-08-20T13:59:17.461675+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via: 2020-08-20T13:59:17.461832+00:00 app[web.1]: npm ERR! npm owner ls slacky-slack 2020-08-20T13:59:17.461982+00:00 app[web.1]: npm ERR! There is likely additional logging output above. 2020-08-20T13:59:17.465485+00:00 app[web.1]: 2020-08-20T13:59:17.465761+00:00 app[web.1]: npm ERR! Please include the following file with any support request: 2020-08-20T13:59:17.465841+00:00 app[web.1]: npm ERR! /app/npm-debug.log 2020-08-20T13:59:17.539236+00:00 heroku[web.1]: Process exited with status 1 2020-08-20T13:59:17.575353+00:00 heroku[web.1]: State changed from starting to crashed 2020-08-20T14:30:18.916030+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=wolfdevchat.herokuapp.com request_id=63128a80-79ec-4fb0-90a3-ee148ca6e8f0 fwd="42.114.34.254" dyno= connect= service= status=503 bytes= protocol=https 2020-08-20T14:30:19.556607+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=wolfdevchat.herokuapp.com request_id=84aafd67-4ea3-42a0-b2b3-8d02f7d4ce4d fwd="42.114.34.254" dyno= connect= service= status=503 bytes= protocol=https
Anyone knows how i can fix it? Thanks in advanced!
@wolfmoonhust could you post the complete log?
Hello, i updated package.json but i got build failed message on heroku with logs:
-----> Building on the Heroku-20 stack -----> Node.js app detected parse error: Expected separator between values at line 46, column 20 ! Unable to parse package.json -----> Build failed We're sorry this build is failing! You can troubleshoot common issues here: https://devcenter.heroku.com/articles/troubleshooting-node-deploys If you're stuck, please submit a ticket so we can help: https://help.heroku.com/ Love, Heroku ! Push rejected, failed to compile Node.js app. ! Push failed
my package.json :
{ "name": "slacky-slack", "version": "1.0.0", "type": "module", "engines": { "node": "6.10.2" }, "description": "Prebuilt api for slack app clone.", "main": "dist", "scripts": { "dev": "NODE_ENV=development nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"", "build": "babel src -s -D -d dist --presets es2015,stage-0", "prestart": "npm run -s build", "start": "node ./dist/index.js", "lint": "eslint src", "test": "echo \"Error: no test specified\" && exit 1" }, "eslintConfig": { "parserOptions": { "ecmaVersion": 7, "sourceType": "module" }, "env": { "node": true }, "rules": { "no-console": 0, "no-unsed-vars": 1 } }, "author": "Jacob Luetzow", "license": "ISC", "dependencies": { "babel-cli": "6.24.1", "babel-core": "6.24.1", "babel-eslint": "7.2.3", "babel-preset-es2015": "6.24.1", "babel-preset-stage-0": "6.24.1", "body-parser": "1.17.1", "express": "4.15.2", "express-jwt": "5.3.0", "jsonwebtoken": "7.4.0", "mongoose": "5.8.3", "passport-local-mongoose": "5.0.0", "mongodb-core": "3.2.7", "passport-local": "1.0.0", "socket.io": "2.0.3", "uniq": "^1.0.1" }, "devDependencies": { "eslint": "3.19.0", "nodemon": "1.11.0" } }
There are syntax errors in this JSON file, double quotes are not escaped on lines 11 and 16.
Line 11 should be:
"dev": "NODE_ENV=development nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"",
Line 16 should be:
"test": "echo \"Error: no test specified\" && exit 1"
I think your problem is this:
2021-02-04T13:52:39.821782+00:00 app[web.1]: MongooseError: The uri parameter to openUri() must be a string, got "undefined". Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string.
Make sure you supply the (correct) connection string to your MongoDB. Do a search for mongoUrl
and see what it is being set to.
Just make sure that your connection string follows the format described here
There's a note about special characters.
Hey, thanks a million. I did 2 changes and i honestly dont know which one fixed my issue. Change 1 : adding { useNewUrlParser: true },{ useMongoClient: true } in connect method.
change 2 : added ' ' to my password in my URL like this example (username and password are not mine, its some random sample text):
"mongoUrl": "mongodb+srv://imUser:'AbCd6Fc499Hi'>@mongodbtest.yxsef.mongodb.net/<database?retryWrites=true&w=majority",
Well now i have a different problem altogether. i have my api url taken from heroku>settings>you app can be found at and hit it with register api via postman, only to get 404 in response and this is what heroku application log says:
at=info method=POST path="/v1/account/register" host=herokumongodbsmackchatterchat.herokuapp.com request_id=ad176ee8-bdbe-42a7-8efa-62999f65186c fwd="123.777.777.777" dyno=web.1 connect=0ms service=65ms status=404 bytes=403 protocol=https
Something must be wrong with your Heroku settings. If you just go to the base url of your app in a browser, you should see this:
{"message":"Chat API is ALIVE!"}
but when I went to your base url: https://herokumongodbsmackchatterchat.herokuapp.com, I got 404 and a stock Heroku page "There's nothing here, yet"
I couldn't find anywhere in the chat API where it would respond with 404, so it must be some configuration issue with your Heroku account.
You tried visiting the url i gave ? oops, I changed it thinking it may lead to some sort of security issues. This is my actual app URL : https://herokumongodbsmackchat.herokuapp.com/
and i do see this : {"message":"Chat API is ALIVE!"} but 404 on Postman when i try :
https://herokumongodbsmackchat.herokuapp.com/v1/account/register from the examples.
Well, that one "is alive".
So are you saying the app is returning 404 only for the "register" endpoint?
2 of the GET , 3 of the POST methods I tried met same fate. So i guess all of the API s ?!
The only condition I can foresee wheree the '/' route is working, but the others do not, is some kind of mongodb connection problem.
Check your app log for "Database connection ready"
Nope. I just checked. Here's what i have :
[import express from 'express'; import config from '../config'; import middleware from '../middleware'; import initalizeDb from '../db'; import user from '../controller/user'; import account from '../controller/account'; import channel from '../controller/channel'; import message from '../controller/message';
let router = express();
//connect to db initalizeDb(db => {
//internal middleware router.use(middleware({ config, db }));
//api routes v1 (/v1) router.use('/user', user({ config, db })); router.use('/account', account({ config, db })); router.use('/channel', channel({ config, db })); router.use('/message', message({ config, db })); });
export default router;](url)
So I was able to reproduce 404 error when I put a simulated delay in the db connection. If mongoose.connect
in db.js doesn't return (right away or ever?) you end up in a situation when only the '/' route will work and the others will return 404.
Okay, but in Postman I get 404 even under 2 seconds
So do you see "Database connection ready" in the log?
What matters is not how long it takes to respond to an HTTP request, but how long it takes to connect to mongodb.
If you don't see "Database connection ready", try your db connection string in Compass.
I re-ran code after adding { useUnifiedTopology: true } to mongoose.connect only because it was suggested on the logs, and this is my heroku logs:
2021-02-06T21:14:53.000000+00:00 app[api]: Build started by user sumukh.abcd@gmail.com
2021-02-06T21:15:16.025214+00:00 heroku[web.1]: Restarting
2021-02-06T21:15:16.029708+00:00 heroku[web.1]: State changed from up to starting
2021-02-06T21:15:17.118022+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-02-06T21:15:15.859539+00:00 app[api]: Release v14 created by user sumukh.aithal@gmail.com
2021-02-06T21:15:17.266999+00:00 heroku[web.1]: Process exited with status 143
2021-02-06T21:15:15.859539+00:00 app[api]: Deploy 3ecf9a41 by user sumukh.abcd@gmail.com
2021-02-06T21:15:18.636106+00:00 heroku[web.1]: Starting process with command `npm start`
2021-02-06T21:15:18.000000+00:00 app[api]: Build succeeded
2021-02-06T21:15:21.619026+00:00 app[web.1]:
2021-02-06T21:15:21.619054+00:00 app[web.1]: > slacky-slack@1.0.0 prestart /app
2021-02-06T21:15:21.619055+00:00 app[web.1]: > npm run -s build
2021-02-06T21:15:21.619055+00:00 app[web.1]:
2021-02-06T21:15:23.620568+00:00 app[web.1]: src/config/index.js -> dist/config/index.js
2021-02-06T21:15:23.917274+00:00 app[web.1]: src/controller/account.js -> dist/controller/account.js
2021-02-06T21:15:24.044840+00:00 app[web.1]: src/controller/channel.js -> dist/controller/channel.js
2021-02-06T21:15:24.117714+00:00 app[web.1]: src/controller/extensions/userData-ext.js -> dist/controller/extensions/userData-ext.js
2021-02-06T21:15:24.296400+00:00 app[web.1]: src/controller/message.js -> dist/controller/message.js
2021-02-06T21:15:24.465160+00:00 app[web.1]: src/controller/user.js -> dist/controller/user.js
2021-02-06T21:15:24.519737+00:00 app[web.1]: src/db.js -> dist/db.js
2021-02-06T21:15:24.602766+00:00 app[web.1]: src/index.js -> dist/index.js
2021-02-06T21:15:24.630620+00:00 app[web.1]: src/middleware/authMiddleware.js -> dist/middleware/authMiddleware.js
2021-02-06T21:15:24.652663+00:00 app[web.1]: src/middleware/index.js -> dist/middleware/index.js
2021-02-06T21:15:24.677742+00:00 app[web.1]: src/model/account.js -> dist/model/account.js
2021-02-06T21:15:24.704034+00:00 app[web.1]: src/model/channel.js -> dist/model/channel.js
2021-02-06T21:15:24.752556+00:00 app[web.1]: src/model/message.js -> dist/model/message.js
2021-02-06T21:15:24.783717+00:00 app[web.1]: src/model/user.js -> dist/model/user.js
2021-02-06T21:15:24.828602+00:00 app[web.1]: src/routes/index.js -> dist/routes/index.js
2021-02-06T21:15:24.863164+00:00 app[web.1]:
2021-02-06T21:15:24.863172+00:00 app[web.1]: > slacky-slack@1.0.0 start /app
2021-02-06T21:15:24.863173+00:00 app[web.1]: > node ./dist/index.js
2021-02-06T21:15:24.863173+00:00 app[web.1]:
2021-02-06T21:15:26.271427+00:00 app[web.1]: Started on port 55440
2021-02-06T21:15:26.326261+00:00 app[web.1]: (node:38) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
2021-02-06T21:15:26.737056+00:00 heroku[web.1]: State changed from starting to up
2021-02-06T21:15:28.970599+00:00 app[web.1]: (node:38) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: callback is not a function
2021-02-06T21:15:37.216680+00:00 heroku[router]: at=info method=GET path="/" host=herokumongodbsmackchat.herokuapp.com request_id=07df9b72-f6d2-4c33-b0f0-8635c162a76e fwd="103.777.777.777" dyno=web.1 connect=0ms service=18ms status=304 bytes=150 protocol=https
2021-02-06T21:15:58.686858+00:00 heroku[router]: at=info method=GET path="/v1/user" host=herokumongodbsmackchat.herokuapp.com request_id=568ce1a9-691f-4fdf-b91a-fd17b833dcfb fwd="103.777.777.777" dyno=web.1 connect=1ms service=8ms status=404 bytes=390 protocol=https
Here's your problem:
2021-02-06T21:15:28.970599+00:00 app[web.1]: (node:38) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: callback is not a function
So interestingly, it doesn't crash the whole process, but prevents the code that builds the routes from executing.
You probably should try to debug it on a local server. Since there's neither mongo url nor "Database connection ready" messages, it seems likely that this exception is thrown from somewhere inside the mongoose.connect
call, and this "callback" it is referring to is not the callback
argument passed to the exported function in db.js
Okay. while I understand what you are trying to say, I'm a no show when it comes to js. Here I'm attaching my code , if you can look into it and let me know the fix it will be a great deal of help. I can't spend a lot of time on fixing a js code issue while I'm actually trying to learn Kotlin and move ahead in that direction. Thanks a lot, my man.
I found a problem in your code:
mongoose.connect(config.mongoUrl, { useNewUrlParser: true },{ useMongoClient: true },{ useUnifiedTopology: true },function (err, database)...
mongoose.connect
takes 3 arguments:
but you are passing 5, so it thinks that { useMongoClient: true}
is the callback function! And that was the source of that "TypeError: callback is not a function" error.
You should pass all options as one object, not three:
mongoose.connect(config.mongoUrl, { useNewUrlParser: true, useMongoClient: true, useUnifiedTopology: true }, function (err, database)...
Now, the useMongoClient
option is unnecessary, and mongoose will complain:
WARNING: The `useMongoClient` option is no longer necessary in mongoose 5.x, please remove it.
Secondly, a word of caution -- ‼️NEVER ‼️commit to github any private information, such as the password in the mongodb connection string in your case.
And finally, there's still a problem with your password/database name --
Why do you have < > and ' ' around your password and < > around your database name?
Your connection string (in config/db.js) should be (pasting it here with the full password, as it is already in the open):
mongoUrl:
'mongodb+srv://testUser:HTh5MyH3A10RSznM@mongodbtest.yxsef.mongodb.net/database?retryWrites=true&w=majority', //"mongodb+srv://testUser:<FWEMXfr2eh4wdgBA>@mongodbtest.yxsef.mongodb.net/<test-db>?retryWrites=true&w=majority"
and probably your database shouldn't be named "database", but something more specific to the application.
Don't forget to change you mongodb password after you got it all straightened out!
Wow ! it worked like a charm. You have no idea how helpful you were to me ! I don't even know your name but you have made a significant impact on my learning curve today. Thanks a million. I never wanted to share usernames and password but I did that anyway out of desperation for help. Because the app I 'm going to build using this API was almost a real app with actually working, useful functionalities which would make an instant impact on my coding confidence. I have already changed my password, API is up and running and I made a couple of successful POST queries. So, shout out for a coding ninja who helped my Kotlin course. May you have a hugely successful career and a peaceful life :)
Forgot to mention : Once I pushed my code to Git with password I received a mail by GitGuardian saying: GitGuardian has detected the following MongoDB URI exposed within your GitHub account.
So when I enabled few options from that mail, I thought it straighten out my mistake.
Well, good luck with your Kotlin endeavors!
Hello , please I need help , because I can go further in the Kotlin course, In fact, after I followed all the steps exactly as mentionned by JohnnyB, when I want to start the app in Heroku I get this erro , (I am using the free way, without a credit card )
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. You can do this from the Heroku CLI with the command heroku logs --tail