goldbergyoni / goldbergyoni/nodebestpractices

Prefer cross-platform API when possible

Open
#1,014 6 comments 3 reactions 0 assignees View on GitHub
Dominant language
Dockerfile
Stars
106k
Forks
10.7k
PR merge metrics
No merged PRs in 30d

Description

- Prefer to use Uint8Array over Buffer whenever possible - bundle buffer into browser is not that good of idea
- Buffer is bloated with something DataView, TextEncoder, TextDecoder is suppose to handle
- Use ArrayBuffer.isView or instancesof Uint8Array checks instead of using Buffer.isBuffer
- Use the Spec'ed EventTarget instead of EventEmitter (again Deno and browser don't have EventEmitter)
- To be Isomorphic across whatwg stream and node streams, prefer async iterator instead, this don't require you to import the hole `node:stream` package into browser and you will be more acceptable of more formats such as async generators that are not only limited to streams. If you are using `for await (let chunk of iterable)` then you can handle `node:streams` whatwg streams and any simple generator the same way
- Don't use node's Url or querystring
- The WHATWG URL Standard uses a more selective and fine grained approach to selecting encoded characters than that used by the Legacy API.
- WHATWG URL and URLSearchParams is available in more environments
- querystring will mix the value between string and arrays giving you an inconsistent api
- Don't use node's string_decoder, use TextDecoder instead (same goes for encoder)
- Don't use util.inherits use extend instead

Contributor guide

No contributing guide indexed for this repository

Research direction

No file, test, or entry point is named in the issue. Start by locating the best-practice sections covering Buffer, EventEmitter, streams, URL/querystring, string_decoder, and util.inherits; done means those sections consistently recommend cross-platform alternatives without changing unrelated guidance.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.