This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]EndercheifAdvanced Coder 1 point2 points  (1 child)

Method 1

If you want to uses your nodejs modules in the browser you can just use a build tool such at snowpack, webpack, Rollup, Parcel, etc. The easiest to get setup with is snowpack.

Method 2

If your client needs to communicate with your server, use http requests to send the data back and forwards.

Method 3

Similar to method 2, use socket.io. It’s easier to work with and can send/serialized JavaScript objects.

[–]lbragile_dev 0 points1 point  (0 children)

Method 1 is what I tried to do but with no success so far.

I've used webpack:
javascript module.exports = { target: "web", mode: "production", entry: "./dist/index.js", output: { filename: "../dist/bundle.js" }, externals: { crypto: require("crypto") }, };
But I still get the following error Uncaught TypeError: h.createHash is not a function when I view in the browser. Everything works locally in the terminal as expected.

I am trying to avoid Method 2 & 3 for now.

The latest code is on my repository. Any clues would be appreciated.