Fix end of file handling and export as node module if loaded within node