While connection setup ssl certificate file error too long

 const client = await MongoClient.connect(uri, {
      useNewUrlParser: true,
      ssl: true,
      sslValidate: true,
      sslCert: fs.readFileSync("./rootCA.pem"),
    });

error: ENAMETOOLONG: name too long

sslCert should be the path to the certificate, you’re passing the contents of the file.