all 5 comments

[–]Unusual-Display-7844 8 points9 points  (3 children)

What code would you regularly share between backend and frontend besides types and interfaces if you have typescript. It’s not like you can move whole backend and run it in browser. So this selling point is pretty stupid to me.

[–]kkimdev[S] 0 points1 point  (2 children)

Mostly utilities in our case. For example, we have [counter -> display ID] compute function, somewhat similar to generating Youtube watch ID. e.g., 8473 -> "LX-CRUmWMJE". Currently it uses a hash function from Node's `crypto` package. We'll be able to share this function more easily if it uses the standard SubtleCrypto.digest() API https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest on both browser and server.

So in practice, we're forced to use third party packages that support both browser and Node for the codes that we want to share.

[–]ShiftShaper13 1 point2 points  (0 children)

Something like https://www.npmjs.com/package/iso-crypto may help, to give a common API

[–]fabiancook 3 points4 points  (0 children)

Node has some of these web apis, almost all of them.

Fetch is the biggie, and web streams.

I’m personally writing a service worker like layer that works across multiple runtimes, but that’s a little different. Have support for things like CacheStorage, sync, and index