You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

双盘笔记本中.npm cache与node_modules的最优存储位置及优化建议

Optimizing npm Performance on Your Dual-Drive Laptop

Awesome question—let's dive into tuning your npm setup for that 256GB SSD + 1TB HDD laptop (with /home on HDD) and nvm usage. We'll cover cache, node_modules placement, and extra tweaks to get the best speed possible.

.npm Cache: Move It to the SSD

Looking at your npm config, your current cache is stored on the HDD at /home/username/.npm:

cache = "/home/username/.npm"

npm's cache gets a ton of read/write activity—downloading package tarballs, storing cached versions, etc.—so moving this to your SSD will make installs, updates, and package lookups way faster. Here's how to do it:

  1. First, pick a spot on your SSD for the cache. Let's assume your SSD is mounted at /mnt/ssd (adjust this path to match your actual SSD mount point):
    mkdir -p /mnt/ssd/npm-cache
    
  2. Update your npm config to use this new SSD-based cache:
    npm config set cache /mnt/ssd/npm-cache --global
    
  3. Verify the change worked by running npm config get cache—it should return your new SSD path.

node_modules: Optimize Global and Project-Specific Locations

Global Packages (Managed by NVM)

Your current global package prefix is set to the HDD:

prefix = "/home/username/.nvm/versions/node/v10.15.3"

Since global packages are accessed frequently, moving your entire nvm installation to the SSD will speed up global installs and module loading. Here's how:

  • Close all terminal windows to make sure no node processes are running.
  • Copy your existing nvm folder to the SSD:
    cp -r /home/username/.nvm /mnt/ssd/.nvm
    
  • Edit your shell config file (.bashrc, .zshrc, or whatever you use) to update the NVM_DIR environment variable:
    export NVM_DIR="/mnt/ssd/.nvm"
    
  • Restart your terminal, then check echo $NVM_DIR and nvm ls to confirm everything still works as expected.

Project-Specific node_modules

If your projects live on the HDD (since /home is there), installing node_modules directly to the HDD will be slow. You have two solid options:

  1. Move high-priority projects to the SSD: If you're actively working on a project that needs frequent dependency updates or fast module access, just move the whole project folder to your SSD (e.g., /mnt/ssd/projects/my-cool-app). This is the simplest, most straightforward fix for performance-critical projects.

  2. Use symlinks to keep projects on HDD, node_modules on SSD: For projects you want to keep on the HDD, create a node_modules directory on the SSD and symlink it to your project:

    # Create a directory for this project's node_modules on SSD
    mkdir -p /mnt/ssd/project-node-modules/my-cool-app
    # Navigate to your project on HDD
    cd /home/username/projects/my-cool-app
    # Remove any existing node_modules folder
    rm -rf node_modules
    # Create the symlink
    ln -s /mnt/ssd/project-node-modules/my-cool-app node_modules
    

    Now when you run npm install, all dependencies will be stored on the SSD, but your project files stay right where they are on the HDD.

Extra Tips for Even Better Performance

  • Stick with package-lock.json: You already have package-lock = true enabled in your config—great! This file speeds up installs by skipping dependency resolution on every run, since npm can just use the exact versions from the lockfile.
  • Use npm ci instead of npm install: For clean, fast installs (especially in CI environments or when setting up a project for the first time), npm ci uses the lockfile directly and skips redundant steps.
  • Clean up old cache: Periodically run npm cache clean --force to remove stale packages and free up space on your SSD.
  • Try a faster package manager: Tools like pnpm use hardlinks to share dependencies across projects, saving space and drastically speeding up installs. yarn also offers faster install times than npm in many cases.
  • Leverage shared stores: If you use pnpm, it automatically uses a shared store for dependencies. For npm, you can look into tools like npm-cache to share cached packages across projects.

内容的提问来源于stack exchange,提问作者KiriSakow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 06:38:09