Let's start with a simple script and we can debug your one later
I just installed mongoose in the instance and created this script
var mongoose = require('mongoose');
Then run it and it worked properly, please change the password and try to use that script. It should keep the connection open.