Error: connect ECONNREFUSED 127.0.0.1:27017 - node.js

I am having this error popped up whenever I try to connect to my mongo Server from mongoose.
I have also tried using different port numbers and deleting the DB file and recreating it. But still the same error log
terminal output
UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
at NativeConnection.Connection.openUri (/home/Desktop/CRUDJS/node_modules/mongoose/lib/connection.js:797:32)
at /home/Desktop/CRUDJS/node_modules/mongoose/lib/index.js:332:10
at /home/Desktop/CRUDJS/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (/home/Desktop/CRUDJS/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/home/Desktop/CRUDJS/node_modules/mongoose/lib/index.js:1153:10)
at Mongoose.connect (/home/Desktop/CRUDJS/node_modules/mongoose/lib/index.js:331:20)
at Object.<anonymous> (/home/Desktop/CRUDJS/app.js:7:10)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
(node:44838) 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:44838) [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.

Related

I've tried connecting my mongoose to my express app, using the following, it'd then connect at first and then state error later on

Code:
mongoose.connect('mongodb://localhost:27017/blog'), {
useUnifiedTopology: true,
useNewUrlParser: true,
}
console.log('MongoDB connected successfully!!');
output:
MongoDB connected successfully!!
(node:2868) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
at NativeConnection.Connection.openUri (C:\Users\v\Desktop\News Blog\node_modules\mongoose\lib\connection.js:824:32)
at C:\Users\v\Desktop\News Blog\node_modules\mongoose\lib\index.js:381:10
at C:\Users\v\Desktop\News Blog\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
at new Promise (<anonymous>)
at promiseOrCallback (C:\Users\v\Desktop\News Blog\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10)
at Mongoose._promiseOrCallback (C:\Users\v\Desktop\News Blog\node_modules\mongoose\lib\index.js:1234:10)
at Mongoose.connect (C:\Users\v\Desktop\News Blog\node_modules\mongoose\lib\index.js:380:20)
at Object.<anonymous> (C:\Users\v\Desktop\News Blog\server.js:7:10)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2868) 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:2868) [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.

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'findIndex' of undefined..... IN MY NODEJS Project

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'findIndex' of undefined
at User.addToCart (D:\Pradip_All\Nodejs- tutorials video (MONGODB)\models\user.js:20:46)
at D:\Pradip_All\Nodejs- tutorials video (MONGODB)\controllers\shop.js:70:23
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11212) 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:11212) [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.
ERROR DESCRIPTION
You should add the ? optional chaining operator that check if the value exists in the object.
const cartProductIndex = this.cart?.items?.findIndex((cp) => {
return cp.productId.toString() === product._id.toString()
})

I'm getting an error using aeproject test command with initialized project

I installed aeproject by doing:
$ npm install -g aeproject
Initiallized my project with
$ aeproject init
And when I want to test it with
$ aeproject test
I get the following error:
(node:68448) UnhandledPromiseRejectionWarning:
/Users/meli/MyStuff/MyAE/ae_tutorial1/node_modules/aeproject-lib/dist/aeproject-deployer.js:1
Error: Cannot find module 'aeproject-utils' Require stack:
/Users/meli/MyStuff/MyAE/ae_tutorial1/node_modules/aeproject-lib/dist/aeproject-deployer.js
/Users/meli/MyStuff/MyAE/ae_tutorial1/node_modules/aeproject-lib/dist/index.js
/Users/meli/MyStuff/MyAE/ae_tutorial1/test/exampleTest.js
/usr/local/lib/node_modules/aeproject/node_modules/mocha/lib/mocha.js
/usr/local/lib/node_modules/aeproject/node_modules/mocha/index.js
/usr/local/lib/node_modules/aeproject/aeproject-test/aeproject-test.js
/usr/local/lib/node_modules/aeproject/aeproject-test/test.js
/usr/local/lib/node_modules/aeproject/commands.js
/usr/local/lib/node_modules/aeproject/aeproject-cli.js
at Object. (/Users/meli/MyStuff/MyAE/ae_tutorial1/node_modules/aeproject-lib/dist/aeproject-deployer.js:21:43)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) (Use node --trace-warnings ... to show where the warning was created) (node:68448)
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) (node:68448) [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.
You can fix this issue by doing
$ npm install aeproject-utils prompts aeproject-logger

UnhandledPromiseRejectionWarning: MongoParseError: Invalid connection string

when i am running my app.js file i am getting UnhandledPromiseRejectionWarning: MongoParseError: Invalid connection string.
the whole error in my terminal is:
$ node app.js
(node:18676) UnhandledPromiseRejectionWarning: MongoParseError: Invalid connection string
at parseConnectionString (C:\Users\Dell\Documents\Extra\fruit\node_modules\mongodb\lib\core\uri_parser.js:565:21)
at connect (C:\Users\Dell\Documents\Extra\fruit\node_modules\mongodb\lib\operations\connect.js:282:3)
at C:\Users\Dell\Documents\Extra\fruit\node_modules\mongodb\lib\mongo_client.js:224:5
at maybePromise (C:\Users\Dell\Documents\Extra\fruit\node_modules\mongodb\lib\utils.js:665:3)
at MongoClient.connect (C:\Users\Dell\Documents\Extra\fruit\node_modules\mongodb\lib\mongo_client.js:220:10)
at C:\Users\Dell\Documents\Extra\fruit\node_modules\mongoose\lib\connection.js:820:12
at new Promise ()
at NativeConnection.Connection.openUri (C:\Users\Dell\Documents\Extra\fruit\node_modules\mongoose\lib\connection.js:817:19)
at C:\Users\Dell\Documents\Extra\fruit\node_modules\mongoose\lib\index.js:345:10
at C:\Users\Dell\Documents\Extra\fruit\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:5
at new Promise ()
at promiseOrCallback (C:\Users\Dell\Documents\Extra\fruit\node_modules\mongoose\lib\helpers\promiseOrCallback.js:30:10)
at Mongoose._promiseOrCallback (C:\Users\Dell\Documents\Extra\fruit\node_modules\mongoose\lib\index.js:1135:10)
at Mongoose.connect (C:\Users\Dell\Documents\Extra\fruit\node_modules\mongoose\lib\index.js:344:20)
at Object. (C:\Users\Dell\Documents\Extra\fruit\app.js:3:10)
at Module._compile (internal/modules/cjs/loader.js:1076:30)
(Use node --trace-warnings ... to show where the warning was created)
(node:18676) 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: 3)
(node:18676) [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.
(node:18676) UnhandledPromiseRejectionWarning: MongooseError: Operation fruits.insertOne() buffering timed out after 10000ms
at Timeout. (C:\Users\Dell\Documents\Extra\fruit\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:184:20)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
(node:18676) 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: 4)
The Code is given below:
const mongoose=require('mongoose');
mongoose.connect('monogodb://localhost:27017/fruitsDB',{ useNewUrlParser:true,family:4});
const fruitSchema=new mongoose.Schema({
name:String,
rating:Number,
review:String
});
const Fruit=mongoose.model("Fruit",fruitSchema);
const fruit=new Fruit({
name:"Apple",
rating:7,
review:"Pretty Good!"
});
fruit.save();
You have a typo at the beginning of your connection string, monogodb instead of mongodb.
Solution make sure your MongoDB URL connection string is correct or misspelled
"mongodb://myDBReader:D1fficultP%40ssw0rd#mongodb0.example.com:27017/?authSource=admin" or
"mongodb://mongodb0.example.com:27017"

Google Sheets node.js api gives an error "Unhandled promise rejection" when attempting to output changed spreadsheet data to console

function checkForChanges() {
let spreadsheetId = '1oHNELBZ3zV4PQBVsJrtqX4Cz00IFmJG_2SaJ4bgTa3c'
let ranges = ['A2:P2', 'A3:P3', 'A4:P4', 'A5:P5']
this.batchGet ({
spreadsheetId,
ranges,
}, (err, result) => {
if (err) {
console.log(err);
} else {
console.log(`${result.valueRanges.length} ranges retrieved.`);
}
})
}
client.on('ready', () => {
while (true) {
checkForChanges();
}
});
I'm expecting that when I change something on the spreadsheet that it returns in console with what was changed. but instead I get this error when i run the program:
[nodemon] starting `node --inspect turnip_bot.js`
Debugger listening on ws://127.0.0.1:9229/b52c6ec8-70cb-451a-9b70-fc8bada920fc
For help, see: https://nodejs.org/en/docs/inspector
(node:1200) UnhandledPromiseRejectionWarning: TypeError: this.batchGet is not a function
at checkForChanges (D:\Programing\Node.js\Discord-Turnip-Bot\turnip_bot.js:72:7)
at Client.<anonymous> (D:\Programing\Node.js\Discord-Turnip-Bot\turnip_bot.js:87:3)
at Client.emit (events.js:323:22)
at WebSocketManager.triggerClientReady (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:433:17)
at WebSocketManager.checkShardsReady (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:417:10)
at WebSocketShard.<anonymous> (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:199:14)
at WebSocketShard.emit (events.js:311:20)
at WebSocketShard.checkReady (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:466:12)
at WebSocketShard.onPacket (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:438:16)
at WebSocketShard.onMessage (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
(node:1200) 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:1200) [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.
I took the code off of the google sheets API quickstart and edited it slightly for my use case and used some of the documentation to help with reading the spreadsheet on mutiple rows.
If I run the sample it returns:
[nodemon] starting `node --inspect google_sheets_api_sample.js`
Debugger listening on ws://127.0.0.1:9229/04ef1aed-3c10-40e5-b8f2-78782b5537bc
For help, see: https://nodejs.org/en/docs/inspector
(node:3208) UnhandledPromiseRejectionWarning: Error: authentication failed
at authorize (D:\Programing\Node.js\Discord-Turnip-Bot\google_sheets_api_sample.js:57:11)
at main (D:\Programing\Node.js\Discord-Turnip-Bot\google_sheets_api_sample.js:13:28)
at Object.<anonymous> (D:\Programing\Node.js\Discord-Turnip-Bot\google_sheets_api_sample.js:42:1)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
(node:3208) 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)
(node:3208) [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

Resources