Node.js

Using Corepack

While browsing the metamask-extension source code, I saw a field in package.json: “packageManager”: “yarn@4.9.1”, but when checking yarn on npm, the latest version is still 1.22.22. Strange, so how does the actual project install this v4 yarn? After careful investigation, I found that it uses corepack for package manager and version management.

Aug 12, 2025

Once Handling in EventEmitter

EventEmitter Initial Version class EventEmitter{ constructor(){ this.events={} } on(type,listener){ if(!this.events[type]){ this.events[type]=[] } this.events[type].push(listener) } emit(type,...args){ this.events[type].forEach(listener=>{ listener.call(this,...args) }) } off(type,listener){ if(this.events[type]){ const index=this.events[type].indexOf(listener) if(index!==-1){ this.events[type].splice(index,1) } } } once(type,listener){ const onceListener=(...args)=>{ listener.call(this,...args) this.off(type,onceListener) } this.on(type,onceListener) } }

Mar 18, 2025

npm Cache

When developing with npm, you may notice that if you delete the node_modules folder and then reinstall dependencies, the installation is very fast. This is because npm has a caching mechanism.

Feb 13, 2025

Understanding peerDependencies

Besides dependency and devDependency in package.json, there’s also peerDependency. Let’s resolve a real-world error to understand how it works. Error Message npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: a@0.0.1-beta npm ERR! Found: ssh2@1.15.0 npm ERR! node_modules/ssh2 npm ERR! ssh2@"1.15.0" from the root project npm ERR! ssh2@"^1.12.0" from ssh2-sftp-client@9.1.0 npm ERR! node_modules/ssh2-sftp-client npm ERR! ssh2-sftp-client@"^9.1.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer ssh2@"1.16.0" from a@0.0.1-beta npm ERR! packages/a npm ERR! a@0.0.1-beta npm ERR! node_modules/a npm ERR! workspace packages/a from the root project npm ERR! npm ERR! Conflicting peer dependency: ssh2@1.16.0 npm ERR! node_modules/ssh2 npm ERR! peer ssh2@"1.16.0" from a@0.0.1-beta npm ERR! packages/a npm ERR! a@0.0.1-beta npm ERR! node_modules/a npm ERR! workspace packages/a from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! npm ERR! For a full report see: npm ERR! /Users/alanhe/.npm/_logs/2025-01-02T02_53_13_141Z-eresolve-report.txt npm ERR! A complete log of this run can be found in: npm ERR! /Users/alanhe/.npm/_logs/2025-01-02T02_53_13_141Z-debug-0.log

Jan 2, 2025

Security Component Scanning and Handling in Node Projects

This article introduces security component scanning and handling in Node projects, including its advantages, implementation details, and relevant resources. These steps can help improve efficiency when handling security component scanning in Node projects.

Jun 2, 2024

File Contents Cleared When Writing via Stream

Investigating why streaming writes cleared file contents when using SFTP in Node.js — the 'w' flag truncation and how it flows through.

Apr 27, 2024

Loading ES Modules in Node.js Projects

This article introduces loading ES modules in Node.js projects, including its advantages, implementation details, and relevant resources. These steps can help improve efficiency when loading ES modules in Node.js projects.

Apr 10, 2024

An Introduction to the ssh2 Package

A practical overview of the ssh2 package for Node.js, including common usage patterns (Client, shell/exec, HTTP agent, SFTP, Server), channel concepts, and references.

Jan 14, 2024

The inspect Command in Node

This article introduces the inspect command in Node, including its advantages, implementation details, and relevant resources. These steps can help improve efficiency when using the inspect command in Node.

Dec 20, 2023

Common npm Packages for Frontend Development

This article introduces common npm packages for frontend development, including usage scenarios and implementation details, to improve efficiency in frontend development.

Dec 20, 2023

Cannot use import statement outside a module

This post explains the 'Cannot use import statement outside a module' error, including causes, investigation, and fixes that help resolve build failures efficiently.

Oct 29, 2022

Getting Started with ssh2-sftp-client

Covers common pitfalls and best practices when using ssh2-sftp-client for listing, uploads, downloads, throttling, and resumable transfers.

Jun 12, 2022

npm Development Dependencies

This article introduces npm development dependencies, including their advantages, implementation details, and related resources. These concepts can help improve the efficiency of managing npm development dependencies.

May 26, 2022

Whistle Plugin Development - remote-rules

This article introduces Whistle plugin development for remote-rules, including its advantages, implementation details, and related resources to improve efficiency in Whistle plugin development.

Apr 9, 2022

Understanding process.env.NODE_ENV

Exploring process.env.NODE_ENV: origins, usage scenarios, and practical applications in frontend builds and Node.js development.

Dec 5, 2021

NPM Package Installation - Understanding Warning Messages

This article introduces warning messages encountered during npm package installation, including their causes, implementation details, and related solutions. These steps can help improve the efficiency of npm package installation troubleshooting.

Nov 29, 2021

sideEffects in package.json

An explanation of the sideEffects field in package.json, including its purpose, usage patterns, and how it enables effective tree shaking in Webpack builds.

Jul 18, 2021

Jenkins Continuous Integration - Publishing New NPM Packages

This article provides an introduction to Jenkins continuous integration for publishing new NPM packages, including the advantages, implementation details, and related resources. These steps can help improve efficiency in Jenkins continuous integration for NPM package publishing.

Jan 7, 2021

Package.json Usage Tips and Tricks

Advanced usage tips for package.json beyond basic dependencies, including version enforcement, custom fields, and practical configuration techniques.

Jul 26, 2020

ESLint Shared Configuration

This article introduces ESLint shared configuration, including its advantages, implementation details, and related resources that can help improve efficiency when working with ESLint shared configurations.

Jun 27, 2020

integrity in yarn.lock

What the integrity field in yarn.lock means, how it’s computed, and why not every package has it.

Mar 19, 2020

NPM Dependency Model

This article introduces the npm dependency model, including its advantages, implementation details, and related materials to help improve efficiency in understanding npm dependency models.

Feb 16, 2020

Publishing Public Packages to npmjs

This article introduces publishing public packages to npmjs, including its advantages, implementation details, and relevant resources. These steps can help improve efficiency when publishing public packages to npmjs.

Jan 21, 2020

NPM Indirect Dependency Version Issues

This article introduces NPM indirect dependency version management, including its advantages, implementation details, and related resources, helping developers improve efficiency in handling NPM indirect dependency versions.

Jan 13, 2020

Duplicate identifier LibraryManagedAttributes

This article introduces the solution to the Duplicate identifier LibraryManagedAttributes error, including the advantages, implementation details, and related resources that can help improve efficiency when dealing with this TypeScript compilation issue.

Dec 24, 2019