Could not connect to the servers in your MongoDB Atlas cluster

Encounter this error when trying to connect to the cluster on mongoDB atlas.
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you’re trying to access the database from an IP that isn’t whitelisted. Make sure your current IP address is on your Atlas cluster’s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/

I have whitelisted my IP and I have tried every possible methods I found on the internet, they just don’t work.

const mongoose = require("mongoose");

const port = process.env.PORT || 5000;

const connectionParams = {
    useNewUrlParser: true,
    useCreateIndex: true,
    useUnifiedTopology: true 
}

mongoose
     .connect(process.env.ATLAS_URL, connectionParams)
     .then(() => console.log( 'Database Connected' ))
     .catch(err => console.log( err ));