Error UnhandledPromiseRejectionWarning when I try to launch my Node.js app

Mikael

My code:

const fastify = require('fastify');
const mongoose = require('mongoose');

const app = fastify();

try {
    mongoose.connect('mongodb://localhost:27017/notes_db');
} catch (e) {
    console.error(e);
}

app.get('/', (request, reply) => {
    try{
        reply.send("Olá mundo");
    } catch(e) {
        console.error(e);
    }
})

app.listen(5000, (err, address) => {
    if (err) {
        console.error(err);
        process.exit(1);
    }
    console.log(`Server running on ${address}`);
});

When I run the command npm start or node index.js this error is shown to me:

(node:10332) 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.
Server running on http://127.0.0.1:5000
(node:10332) UnhandledPromiseRejectionWarning: Error: Password contains an illegal unescaped character
    at parseConnectionString (C:\Users\mikae\Desktop\notes-server\node_modules\mongodb\lib\url_parser.js:299:13)
    at parseHandler (C:\Users\mikae\Desktop\notes-server\node_modules\mongodb\lib\url_parser.js:130:14)
    at QueryReqWrap.callback (C:\Users\mikae\Desktop\notes-server\node_modules\mongodb\lib\url_parser.js:114:7)
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:205:10)
(node:10332) 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:10332) [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.

My server is running but I want to know how to fix this message.

domenikk

Can you try specifying the useNewUrlParser option like this:

try {
    mongoose.connect('mongodb://localhost:27017/notes_db', { useNewUrlParser: true });
} catch (e) {
    console.error(e);
}

Edit

Since you're trying to connect to MongoDB Atlas cluster and not local installation, replace the connection URI to the one you get on Atlas.

Here is a tutorial I found: https://medium.com/@sergio13prez/connecting-to-mongodb-atlas-d1381f184369

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

UnhandledPromiseRejectionWarning: Error: Cannot find module '../database/db' when i try to run my code

When I try to use firebase in my flutter app it produces an error

when I am trying to launch my app in my device and I am getting the error as launch option nil in my xcode?

Microsoft VS Code: When I try to launch my program error "spawn php ENOENT" shows up

Error when cordova launch my app

"My App has stopped" error when I try to run my app on a real phone

Getting error when trying to launch node.js app with PM2 Cluster

AWS Missing credentials when i try send something to my S3 Bucket (Node.js)

Getting an error in multi ./src/styles.scss when I try to deploy my angular app to heroku

Why my Swift app throws a fatal error when I try to unwrap the optional?

get() in node.js app is not getting called when I try to hit localhost

Node.js app doesn't work when I try to host it via GCP deploy command. Error: Cannot find module 'express'

Node.js - error on login form UnhandledPromiseRejectionWarning

Android http URL scheme is not working when I try to launch my application from a link on my website

I can not launch my js Discord bot, error message

How would one resolve a 'UnhandledPromiseRejectionWarning' error, while trying to deploy a node.js app?

Why is my try\catch not catching an error in node.js

I have a public folder in my Node.js/Express.js project which contains some images. When I try to access those images through URL, I get 404 error

When i try to refresh my page i have this error

When I try to sync my Gradle files I get an error

When i try to update my json file i get a error

When I try to deploy my PHP application to Google App Engine, why am I suddenly getting a 400 error?

My app crashes when I try to add Image Button to it

App giving bad performace when i try to repeat my action

my app crashes when I try to download an image

My app is crashing when I try to go to another activity

Failed to compile values file' when i try to run my app

Build failed when I try to run my flutter app

My app crashes when i try to move to a particular layout