You're trying to implement server-side code (with nodeJS modules) within a browser client context. If you want to make this you can use server side engines like expressjs