Fixed problem with missing document variable in NodeJS