Added additional check for document for NodeJS environment