How to change the code so that the nodejs connects to a local database instead of a remote one on Atlas?

If your

looks like

Then you are still trying to connect to Atlas. You are not trying to connect to

Visit documentation to see how to connect localhost.