I have a simple codesnippet in a file test.js:
  [1, 2, 3, 4].forEach(function(e) {
        console.log(e);
    });
whenever I run node test.js in terminal I get the output
    1
    2
    3
    4
    |
But the program never really exits. I am required to end it manually. It seems quite trivial but I am unable to figure out a proper way to exit the scrip in the terminal.
UPDATE 1:
var mongoose = require('mongoose');
var User = require('../models/users/user');
var UserProfile = require('../models/users/profile');
var config = require('../config');
var logger = require('../libraries/logger');
logger = logger.createLogger(config);
var connectionString = config.database.adapter + '://' + config.database.host + ':' + config.database.port + '/' + config.database.name;
mongoose.connect(connectionString, {server: {auto_reconnect: true }});
User.find(function(error, users) {
    users.forEach(function(user) {
    var data = {
        email: user.local.email || user.google.email || user.facebook.email || ''
    };
    UserProfile.update({user_id: user._id}, {$set: data}, function (error, record) {
        if (error) {
            logger.error(error);
        } else {
            logger.info(data);
        }
    });
});
Above is the code I am actually trying to make work. Adding process.exit() exits the process even without processing the script. Any solutions?
UPDATE 2:
I figured out the solution. In above case script wasn't exiting because connection to mongodb database wasn't closed.
I used a dirty hack to close the connection after processing is done by adding setTimeout(function() { mongoose.connection.close(); }, 60 * 1000); at the end of the line 
 
     
    