When I try to run a Docker container and connect to a local MongoDB database, it gives me this error:
UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Authentication failed.
this is the connection url in the end: mongodb://pody-admin:Nt4VzWPtDhkCxESjXVJx#localhost:27017/podify
I am trying to get an Auth system that someone else made to work on my end(cloned the repo).
I really don't have experience with working on team projects and using other people's code, let alone Docker.
I'm not really expecting a solution, but would like to know where to look to even understand what might be wrong.
This is what I get in the cmd:
$ npm run up
server#1.0.0 up D:\projects\SOS\podify\Server
docker-compose up -d
Starting server_db_1 ... done
Starting server_cache_1 ... done
server#1.0.0 postup D:\projects\SOS\podify\Server
npm run dev
server#1.0.0 dev D:\projects\SOS\podify\Server
npm run dev --prefix api
api#1.0.0 dev D:\projects\SOS\podify\Server\api
nodemon --exec ts-node src/index.ts
[nodemon] 2.0.4
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: ts,json
[nodemon] starting ts-node src/index.ts
Connection url => mongodb://pody-admin:Nt4VzWPtDhkCxESjXVJx#localhost:27017/podify
(node:5072) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Authentication failed.
at NativeConnection.Connection.openUri (D:\projects\SOS\podify\Server\api\node_modules\mongoose\lib\connection.js:828:32)
at Mongoose.connect (D:\projects\SOS\podify\Server\api\node_modules\mongoose\lib\index.js:335:15)
at D:\projects\SOS\podify\Server\api\src\index.ts:10:20
at Object. (D:\projects\SOS\podify\Server\api\src\index.ts:21:3)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Module.m._compile (D:\projects\SOS\podify\Server\api\node_modules\ts-node\src\index.ts:858:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Object.require.extensions. [as .ts] (D:\projects\SOS\podify\Server\api\node_modules\ts-node\src\index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at main (D:\projects\SOS\podify\Server\api\node_modules\ts-node\src\bin.ts:227:14)
at Object. (D:\projects\SOS\podify\Server\api\node_modules\ts-node\src\bin.ts:513:3)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
(node:5072) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5072) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[nodemon] clean exit - waiting for changes before restart
Related
This question already has answers here:
Why am I getting a ReferenceError: AbortController is not defined in Discord.js v13?
(3 answers)
Closed 1 year ago.
I deployed my discord bot to Heroku but It is giving an error of unhandled promise rejection
Here are the logs
2021-09-10T20:50:26.000000+00:00 app[api]: Build started by user codertanishq#gmail.com
2021-09-10T20:50:45.558185+00:00 app[api]: Deploy c608c194 by user codertanishq#gmail.com
2021-09-10T20:50:45.558185+00:00 app[api]: Release v11 created by user codertanishq#gmail.com
2021-09-10T20:50:46.000000+00:00 app[api]: Build succeeded
2021-09-10T20:50:46.978335+00:00 heroku[web.1]: State changed from crashed to starting
2021-09-10T20:50:48.877754+00:00 heroku[web.1]: Starting process with command `npm start`
2021-09-10T20:50:51.529490+00:00 app[web.1]:
2021-09-10T20:50:51.529505+00:00 app[web.1]: > start#1.0.0 start /app
2021-09-10T20:50:51.529506+00:00 app[web.1]: > node ./src/bot.js
2021-09-10T20:50:51.529506+00:00 app[web.1]:
2021-09-10T20:50:51.762757+00:00 app[web.1]: (node:22) UnhandledPromiseRejectionWarning: ReferenceError: AbortController is not defined
2021-09-10T20:50:51.762758+00:00 app[web.1]: at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:172:15)
2021-09-10T20:50:51.762758+00:00 app[web.1]: at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:176:19)
2021-09-10T20:50:51.762758+00:00 app[web.1]: at RequestHandler.push (/app/node_modules/discord.js/src/rest/RequestHandler.js:50:25)
2021-09-10T20:50:51.762759+00:00 app[web.1]: at async WebSocketManager.connect (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:128:9)
2021-09-10T20:50:51.762759+00:00 app[web.1]: at async Client.login (/app/node_modules/discord.js/src/client/Client.js:245:7)
2021-09-10T20:50:51.762759+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-09-10T20:50:51.763064+00:00 app[web.1]: (node:22) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
2021-09-10T20:50:51.763091+00:00 app[web.1]: (node:22) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2021-09-10T20:50:51.847328+00:00 heroku[web.1]: Process exited with status 0
2021-09-10T20:50:51.902780+00:00 heroku[web.1]: State changed from starting to crashed
You would have to upgrade your node version. You may add the following to your package.json:
"engines": {
"node": "16.9.1",
}
And redeploy your project and it would work
Discord.js v13 needs AbortController to function, but it was only introduced in node versions 16 and above. You have two options to fix this error:
Upgrade your node version on heroku to 16 or above
Use a polyfill for your AbortController , AbortController-polyfill is a package to do that, you may utilise it like so:
const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');
global.AbortController = AbortController;
When I have done everything correctly and have scripted correctly the comes up when i put node . in command prompt I even have a valid token!! ::
(node:8744) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided. at Client.login (C:\Users\User\Documents\GitHub TigerDuo\TigerDuo\node_modules\discord.js\src\client\Client.js:204:52) at Object.<anonymous> (C:\Users\User\Documents\GitHub TigerDuo\TigerDuo\index.js:47:5) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) at Module.load (internal/modules/cjs/loader.js:977:32) at Function.Module._load (internal/modules/cjs/loader.js:877:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) at internal/main/run_main_module.js:18:47 (node:8744) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:8744) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
and this is my script let alone i have setup heroku and github:
const Discord = require('discord.js');
const bot = new Discord.Client();
const token = 'MyNeverToBeSharedToken';
bot.on('ready', () => {
console.log('Online.')
bot.user.setActivity('the Tiger Duo server!', {
type: "WATCHING"
})
bot.login(process.env.token);
Try installing dotenv package
require("dotenv").config()
And add this to the top of your code
Summary: Node/Express API on Cloud Run not connecting to Mongo cluster on MongoDB Atlas
Our Express/Node API is being deployed to Google's new Cloud Run for container deployments. The API, when run locally with docker using docker run -p 8080:8080 <image_id>, fetches data from our Mongo database just fine. The relevant logs from within Cloud Run:
2020-04-22T18:15:15.408778Z(node:1) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connection timed out
2020-04-22T18:15:15.408824Z at new MongooseServerSelectionError (/usr/app/node_modules/mongoose/lib/error/serverSelection.js:22:11)
2020-04-22T18:15:15.408834Z at NativeConnection.Connection.openUri (/usr/app/node_modules/mongoose/lib/connection.js:823:32)
2020-04-22T18:15:15.408844Z at Mongoose.connect (/usr/app/node_modules/mongoose/lib/index.js:333:15)
2020-04-22T18:15:15.408854Z at Object.<anonymous> (/usr/app/models/index.js:11:10)
2020-04-22T18:15:15.408862Z at Module._compile (internal/modules/cjs/loader.js:1123:30)
2020-04-22T18:15:15.408871Z at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
2020-04-22T18:15:15.408880Z at Module.load (internal/modules/cjs/loader.js:972:32)
2020-04-22T18:15:15.408893Z at Function.Module._load (internal/modules/cjs/loader.js:872:14)
2020-04-22T18:15:15.408902Z at Module.require (internal/modules/cjs/loader.js:1012:19)
2020-04-22T18:15:15.408911Z at require (internal/modules/cjs/helpers.js:72:18)
2020-04-22T18:15:15.408919Z at Object.<anonymous> (/usr/app/config/passport.js:7:12)
2020-04-22T18:15:15.408927Z at Module._compile (internal/modules/cjs/loader.js:1123:30)
2020-04-22T18:15:15.408937Z at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
2020-04-22T18:15:15.408946Z at Module.load (internal/modules/cjs/loader.js:972:32)
2020-04-22T18:15:15.408954Z at Function.Module._load (internal/modules/cjs/loader.js:872:14)
2020-04-22T18:15:15.408964Z at Module.require (internal/modules/cjs/loader.js:1012:19)
2020-04-22T18:15:15.608498Z(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2020-04-22T18:15:15.608686Z(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
...
2020-04-22T18:19:59.772303ZGET504296 B300.5 sChrome 81 https://node-api-deploy-q62r35344q-uw.a.run.app/api/cbb/home-page-stats
The request has been terminated because it has reached the maximum request timeout. To change this limit, see https://cloud.google.com/run/docs/configuring/request-timeout
2020-04-22T18:20:26.472145ZGET504290 B300 sChrome 81 https://node-api-deploy-q62r35344q-uw.a.run.app/api/cbb/teams/list
The request has been terminated because it has reached the maximum request timeout. To change this limit, see https://cloud.google.com/run/docs/configuring/request-timeout
This makes it seem clear that the data is not being fetched, and the requests are then timing out. My Mongo database is hosted in MongoDB Atlas, and I haven't done anything in particular (whitelist the IP of the cloud run server, etc.) that I might have to do to make this work. Does cloud run even have an IP, or no because it is serverless. Maybe I have to pass the DB URI to cloud run through an env variable? I'm not sure.
Edit
Here's a relevant Stack Overflow post that also mostly went unanswered.
Cloud Run now has support for configuring VPC egress settings that lets you define a static IP for outbound requests through Cloud NAT. You can follow this step by step guide in the documentation to configure a static IP to whitelist at MongoDB Atlas.
I want to use transactions with mongoose, therefore I installed run-rs to test it in the development stage. According to guides like this one https://medium.com/cashpositive/the-hitchhikers-guide-to-mongodb-transactions-with-mongoose-5bf8a6e22033 run-rs starts it on the localhost. When I run run-rs -v 4.2.5 --keep --shell to start the replica-set via the terminal it says: Started replica set on "mongodb://DESKTOP-U9IDO6F:27017,DESKTOP-U9IDO6F:27018,DESKTOP-U9IDO6F:27019?replicaSet=rs". Why is it saying DESKTOP for me instead of localhost and how would I connect to it in mongoose.connect()?
I tried the following in my index.js:
const app = express();
const PORT = 27017;
const dbUri = 'mongodb://DESKTOP-U9IDO6F:27017,DESKTOP-U9IDO6F:27018,DESKTOP-U9IDO6F:27019?replicaSet=rs'
mongoose.Promise = global.Promise;
mongoose.connect(dbUri, {
replicaSet: 'rs',
useNewUrlParser: true,
useUnifiedTopology: true
});
Also how would I append the databasename?
UPDATE:
PS C:\Users\Workstation\project> npm start
> project#1.0.0 start C:\Users\Workstation\project
> nodemon ./index.js --exec babel-node -e js
[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js
[nodemon] starting `babel-node ./index.js`
Your server is running on Port 4000
(node:7436) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27018
at new MongooseServerSelectionError (C:\Users\Workstation\project\node_modules\mongoose\lib\error\serverSelection.js:22:11)
at NativeConnection.Connection.openUri (C:\Users\Workstation\ project\node_modules\mongoose\lib\connection.js:823:32)
at Mongoose.connect (C:\Users\Workstation\ project\node_modules\mongoose\lib\index.js:333:15)
at Object.<anonymous> (C:/Users/Workstation/project/index.js:22:10)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at loader (C:\Users\Workstation\project\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.<computed> [as .js] (C:\Users\Workstation\project\node_modules\babel-register\lib\node.js:154:7)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
at Object.<anonymous> (C:\Users\Workstation\project\node_modules\babel-cli\lib\_babel-node.js:154:22)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
(node:7436) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7436) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
UPDATE
I accepted the answer below, because the string for connecting works, hence the original question is solved. However I switched to Linux and it works now without further setup. run-rs didn't work on my Windows machine it seems.
replace:
const dbUri = 'mongodb://DESKTOP-U9IDO6F:27017,DESKTOP-U9IDO6F:27018,DESKTOP-U9IDO6F:27019?replicaSet=rs'
with:
const dbUri = 'mongodb://localhost:27017,localhost,localhost:27019/databasenaeme'
Also need to run mongoDb at these port manully. use link for refrence:
link
I am trying to host a bot on heroku (written using node and discord js). The bot itself is working since I can run it locally with no issues but heroku doesn't seem to like it. I've been getting the same error every time I tried to deploy it. I've changed the Procfile file to a worker instead of web application, I have pushed everything + restarted but can't seem to get it to work. Any help?
2020-01-28T11:31:46.007810+00:00 heroku[worker.1]: State changed from crashed to starting
2020-01-28T11:31:48.995011+00:00 heroku[worker.1]: Starting process with command `node index.js`
2020-01-28T11:31:49.818228+00:00 heroku[worker.1]: State changed from starting to up
2020-01-28T11:31:52.030152+00:00 heroku[worker.1]: State changed from up to crashed
2020-01-28T11:31:52.006456+00:00 heroku[worker.1]: Process exited with status 0
2020-01-28T11:31:51.886594+00:00 app[worker.1]: (node:4) UnhandledPromiseRejectionWarning: Error: An invalid token was provided.
2020-01-28T11:31:51.886618+00:00 app[worker.1]: at /app/node_modules/discord.js/src/client/rest/RESTMethods.js:34:54
2020-01-28T11:31:51.886621+00:00 app[worker.1]: at new Promise (<anonymous>)
2020-01-28T11:31:51.886623+00:00 app[worker.1]: at RESTMethods.login (/app/node_modules/discord.js/src/client/rest/RESTMethods.js:33:12)
2020-01-28T11:31:51.886625+00:00 app[worker.1]: at Client.login (/app/node_modules/discord.js/src/client/Client.js:280:30)
2020-01-28T11:31:51.886627+00:00 app[worker.1]: at Object.<anonymous> (/app/index.js:45:8)
2020-01-28T11:31:51.886629+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:955:30)
2020-01-28T11:31:51.886631+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
2020-01-28T11:31:51.886633+00:00 app[worker.1]: at Module.load (internal/modules/cjs/loader.js:811:32)
2020-01-28T11:31:51.886635+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:723:14)
2020-01-28T11:31:51.886637+00:00 app[worker.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
2020-01-28T11:31:51.887556+00:00 app[worker.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
2020-01-28T11:31:51.887666+00:00 app[worker.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
With just the error it is hard to know the exact problem, but I think that you might have given a wrong Token for the bot, check if you didn't ignore the file containing the token.
If you are using a .env file for your token, then you can define environment variables on the app on Heroku.