Fix compilation errors

Fixed some TypeScript compilation errors and reorganized some code in
node/main.ts.

Updated the node and socket.io definition files.