'msg' not defined, how to call .on function on server side?