How to declare database connection globaly in node.js

I'm working with node.js and socket.io using mysql module in it. Is it possible to declare

var connection = mysql.createConnection(database);

as global? rather using it in all functions, so that i can use it in all functions even if each function has

connection.end();

in it??

node.js has GLOBAL as the global to app. So you can do like this.

if (!GLOBAL.connection) {
    GLOBAL.connection = mysql.createConnection(database);
}

and when you like to end connection, use

if (GLOBAL.connection) 
    GLOBAL.connection.end();

You could avoid globals and use this initialize option, keeping global space clean: http://stackoverflow.com/a/18008471/491662