Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

saslprep warning when using MongoClient.connect()

I'm writing a NodeJS/express API and am facing the following warning when connecting to mongo server:

Warning: no saslprep library specified. Passwords will not be sanitized

Found no mention of this warning in documentation or github/google - is that OS (linux) library missing, or node package?

This is the connection code sample:

const client = await MongoClient.connect(`mongodb://${auth[0]}:${auth[1]}@${url}/admin`, {
    useNewUrlParser: true
});
this.db = client.db(database);

How can I get rid of it?

Additional information:

Mongodb server: docker mongo:latest, resolved to 4.0.4 as of now

mongodb library: 3.1.9

like image 222
Grzegorz Judas Avatar asked Nov 12 '18 16:11

Grzegorz Judas


2 Answers

Just install the saslprep package and the warning will go away.

The mongodb package looks for the saslprep package, but works without it; it's an optional dependency.

If you look in the mongodb source:

let saslprep;
try {
  saslprep = require('saslprep');
} catch (e) {

And, later:

if (!saslprep) {
    console.warn('Warning: no saslprep library specified. Passwords will not be sanitized');
}
like image 62
Michael Avatar answered Nov 15 '22 18:11

Michael


Please use this command in your app. It worked for me. Hope it help you.

npm install saslprep --save
like image 35
Pramod Jaiswal Avatar answered Nov 15 '22 19:11

Pramod Jaiswal