362 private links
64-bits pointer address can be compressed to 32 bits
The author creates a project to gather statistics about the top most starred projects on Github or the most downloaded packages on NPM.
- 9-27% of JS/TS projects declare themselves to be ES Modules
- Less than 6% of JS/TS files declare that they are ES Modules via the
.mjs,.cjsor.mtsfile extensions.
Some ideas:
- kill
.mjs,.cjsand.mtsshould be replaced by thetype="module"in package.json. Let's stick to.js,.jsx,.tsand.tsx - Make
type="module"the default and warns when the type is not set to module. - We should upgrade the most common libraries used by the community to ES Modules
- The NPM registry can require an explicit module field on new packages, making it clear when a package intentionally uses CommonJS.
- NodeJS can officially drop support for
requireandmodule.exportsin a future version, creating a bit more pressure to migrate.
Note: "The key insight is that loading massive files into memory all at once is rarely a good idea, even when technically possible."
- Read the whole file and call it a day with
fs.readFile - Read by byte chunks with file handles and buffers
- (preferred) Use stream
The streams handle the bytes and UTF-8 encoding automatically. Each state can be defined with a callback: error, data, end.
Use appropriate buffer sizes for streams. Default is 64kB. The highWaterMark can adjust it though.
When to use streams: large files, real time data processing, memory is limited, composability, unknown file sizes.
When to use file handles: precise control.
When to use fs/promises: known small files. readFileSync() and writeFileSync() are acceptable for cli tools and scripts, but forbidden for web servers and concurrent apps.
Prefer Promise.all or Promise.allSettled to leverage concurrency.
Handle specific errors. Always. await handle.close() or stream.on('error', () => stream.destroy()). Another solution is await pipeline(source, transform, destinationl)
How a rewrite in Rust is beneficial to read many files? Because it avoids allocation.
Note the program was written once in JS then in Rust.
https://youtu.be/LB8KwiiUGy0?t=525
NPM started as a bash script. It's a MVP approach that succeeded.
It seems to be the best package manager as it also includes a way to manage node versions.
It avoid to rely on both npm and nvm for example.
Find unused dependencies: npx depcheck
Or install the package and run the command.
There is also npm-check that checks for outdated, incorrect, and unused dependencies.
Authentication middleware framework
Ok so you can write Rust for Node applications ? :D
Okay so these guys built a WebAssembly based virtual machine to run x86 binaries. SO you can run ANY type of programs in the browser !
An faster alternative to nvm !
Pour les projets perso 💚